Handle errors when generating QR codes

This commit is contained in:
Miraty 2022-06-07 00:05:07 +02:00
parent 80aa7f5e95
commit d0f211f61e
5 changed files with 16 additions and 1 deletions

View file

@ -241,7 +241,14 @@ if ($validFormSubmitted) {
hexdec(substr($params['fgColor'],4,2))
));
$result = $qrCode->build();
try {
$result = $qrCode->build();
} catch (Exception $ex) {
http_response_code(500);
echo "<p><strong>" . $loc['error_generation'] . "</strong></p></body></html>";
error_log("LibreQR encountered an error while generating a QR code: " . $ex);
exit();
}
$dataUri = $result->getDataUri();

View file

@ -37,4 +37,6 @@ $loc = array(
<a href='https://en.wikipedia.org/wiki/QR_code' hreflang='en' rel='help external noreferrer'>QR code on Wikipedia</a>.
",
'metaText_legal' => "LibreQR " . LIBREQR_VERSION . " is a free software whose <a href='https://code.antopie.org/miraty/libreqr/' rel='external noreferrer'>source code</a> is available under the terms of the <abbr title='GNU Affero General Public License version 3 or any later version'><a href='LICENSE.html' hreflang='en' rel='license'>AGPLv3</a>+</abbr>.",
'error_generation' => "An error occurred while generating the QR code. Try with different parameters.",
);

View file

@ -37,4 +37,6 @@ $loc = array(
<a href='https://fr.wikipedia.org/wiki/Code_QR' hreflang='fr' rel='help external noreferrer'>Code QR sur Wikipédia</a>.
",
'metaText_legal' => "LibreQR " . LIBREQR_VERSION . " est un logiciel libre dont le <a href='https://code.antopie.org/miraty/libreqr/' rel='external noreferrer'>code source</a> est disponible selon les termes de l'<abbr title='GNU Affero General Public License version 3 ou toute version ultérieure'><a href='LICENSE.html' hreflang='en' rel='license'>AGPLv3</a>+</abbr>.",
'error_generation' => "Une erreur a eu lieu lors de la génération du code QR. Essayez avec des paramètres différents.",
);

View file

@ -37,4 +37,6 @@ $loc = array(
<a lang='ca' href='https://ca.wikipedia.org/wiki/Codi_QR' hreflang='ca' rel='help external noreferrer'>Còdi QR a la Wikipèdia</a>.
",
'metaText_legal' => "LibreQR " . LIBREQR_VERSION . " es un logicial liure que son <a href='https://code.antopie.org/miraty/libreqr/' rel='external noreferrer'>còdi font</a> es disponible jols tèrmes de la licéncia <abbr title='GNU Affero General Public License version 3 or any later version'><a href='LICENSE.html' hreflang='en' rel='license'>AGPLv3</a>+</abbr>.",
'error_generation' => "An error occurred while generating the QR code. Try with different parameters.",
);

View file

@ -29,4 +29,6 @@ $loc = array(
'metaText_qr' => "metaText_qr",
'metaText_legal' => "metaText_legal",
'error_generation' => "error_generation",
);