Fixing error handling in QrCodeGetController
This commit is contained in:
parent
515dadb319
commit
f2957ab4ad
@ -20,16 +20,23 @@ final class QrCodeGetController extends AbstractController
|
||||
$filename = Setting::PATH_QR_CODES . (string)$this->fingerprintId . '.svg';
|
||||
|
||||
if (!is_file($filename)) {
|
||||
$this->response = new ApiJsonResponse();
|
||||
$this->response = new ApiJsonResponse(ServerStatus::BAD_REQUEST);
|
||||
$this->response->setParameter('success', false);
|
||||
$this->response->setMessage('No QR code for fingerprint id %d found!');
|
||||
$this->response->setMimeType(ApiResponse::MIME_TYPE_JSON);
|
||||
$this->response->setMessage(sprintf('No QR code for fingerprint id %d found!', $this->fingerprintId));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->response = new ApiSvgResponse();
|
||||
try {
|
||||
$this->response = new ApiSvgResponse();
|
||||
|
||||
$file = fopen($filename, 'r');
|
||||
$this->response->setContent(fread($file, filesize($filename)));
|
||||
fclose($file);
|
||||
$file = @fopen($filename, 'r');
|
||||
$this->response->setContent(@fread($file, @filesize($filename)));
|
||||
@fclose($file);
|
||||
} catch (Throwable $e) {
|
||||
$this->response = new ApiJsonResponse(ServerStatus::INTERNAL_ERROR);
|
||||
$this->response->setParameter('success', false);
|
||||
$this->response->setMessage($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user