Fixing error handling in QrCodeGetController

This commit is contained in:
Mal 2020-08-20 16:23:49 +02:00
parent 515dadb319
commit f2957ab4ad
1 changed files with 14 additions and 7 deletions

View File

@ -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());
}
}
}