Adds some primitive error handling
parent
9a5d01899b
commit
59a4fda701
|
|
@ -47,7 +47,9 @@
|
|||
</div>
|
||||
|
||||
<hr>
|
||||
<p id="errors" style="color:Tomato;"></p>
|
||||
<p>Try your QR Code: <div id="qrcode"></div></p>
|
||||
|
||||
<p>Click <button id="upload" class="btn btn-primary">Upload</button></p>
|
||||
|
||||
<script src="../../core/lib/customize.js"></script>
|
||||
|
|
@ -95,6 +97,7 @@
|
|||
return qrstring;
|
||||
}
|
||||
function refreshQRCode(){
|
||||
document.getElementById("errors").innerText="";
|
||||
qrcode.clear(); // clear the code.
|
||||
var qrText = "";
|
||||
if(document.getElementById("useWIFI").checked){
|
||||
|
|
@ -109,10 +112,17 @@
|
|||
}
|
||||
qrcode._htOption.text = qrText;
|
||||
qrcode._htOption.correctLevel = parseInt(document.getElementById("correction").value);
|
||||
qrcode.makeCode(qrText);
|
||||
try {
|
||||
qrcode.makeCode(qrText);
|
||||
} catch (error) {
|
||||
document.getElementById("errors").innerText="Error: QR could not be created.";
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
var integerScale = Math.max(Math.floor(targetSize / (qrcode._oQRCode.moduleCount + 1)),1);
|
||||
|
||||
if (integerScale == 1) document.getElementById("errors").innerText = "Warning, QR will probably be too small to properly scan. Try less data or less error correction.";
|
||||
|
||||
finalSizeQr = integerScale * (qrcode._oQRCode.moduleCount + 1);
|
||||
finalSizeCanvas = finalSizeQr - 1;
|
||||
|
||||
|
|
@ -121,8 +131,12 @@
|
|||
|
||||
document.getElementsByTagName("canvas")[0].width = finalSizeCanvas;
|
||||
document.getElementsByTagName("canvas")[0].height = finalSizeCanvas;
|
||||
|
||||
qrcode.makeCode(qrText);
|
||||
try {
|
||||
qrcode.makeCode(qrText);
|
||||
} catch (error) {
|
||||
document.getElementById("errors").innerText="Error: QR could not be created.";
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
var qrcode;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue