Skip to content

Commit 10af4e3

Browse files
committed
Notify errors
1 parent d3ae575 commit 10af4e3

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

ZplEscPrinter/js/main.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,20 +204,24 @@ async function escpos(data,b64){
204204
await displayEscPosLabel(btoa('<html style="background-color:#f8f8f8;"><head></head><body style="background-color:white;border:1px #dee2e6 solid;"><div style="text-align:center;"><b>-------- PAPER CUT --------</b><br/><br/><div style="width:100px;display:block;margin-left:auto;margin-right:auto;"><svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" version="1.1" width="100" height="60" id="svg2"> <defs id="defs4"> <marker refX="0" refY="0" orient="auto" id="Scissors" style="overflow:visible"> <path d="M 9.0898857,-3.6061018 C 8.1198849,-4.7769976 6.3697607,-4.7358294 5.0623558,-4.2327734 l -8.2124046,3.0779029 c -2.3882933,-1.3067135 -4.7482873,-0.9325372 -4.7482873,-1.5687873 0,-0.4973164 0.4566662,-0.3883222 0.3883068,-1.6831941 -0.065635,-1.2432767 -1.3635771,-2.1630796 -2.5903987,-2.0816435 -1.227271,-0.00735 -2.499439,0.9331613 -2.510341,2.2300611 -0.09143,1.3063864 1.007209,2.5196896 2.306764,2.6052316 1.5223406,0.2266616 4.218258,-0.6955566 5.482945,1.57086006 -0.9422847,1.73825774 -2.6140244,1.74307674 -4.1255107,1.65607034 -1.2548743,-0.072235 -2.7620933,0.2873979 -3.3606483,1.5208605 -0.578367,1.1820862 -0.0112,2.8646022 1.316749,3.226412 1.3401912,0.4918277 3.1806689,-0.129711 3.4993722,-1.6707242 0.2456585,-1.187823 -0.5953659,-1.7459574 -0.2725074,-2.1771537 0.2436135,-0.32536 1.7907806,-0.1368452 4.5471053,-1.3748244 L 5.6763468,4.2330688 C 6.8000164,4.5467672 8.1730685,4.5362646 9.1684433,3.4313614 L -0.05164093,-0.05372222 9.0898857,-3.6061018 z m -18.3078016,-1.900504 c 1.294559,0.7227998 1.1888392,2.6835702 -0.1564272,3.0632889 -1.2165179,0.423661 -2.7710269,-0.7589694 -2.3831779,-2.0774648 0.227148,-1.0818519 1.653387,-1.480632 2.5396051,-0.9858241 z m 0.056264,8.0173649 c 1.3508301,0.4988648 1.1214429,2.7844356 -0.2522207,3.091609 -0.9110594,0.3163391 -2.2135494,-0.1387976 -2.3056964,-1.2121394 -0.177609,-1.305055 1.356085,-2.4841482 2.5579171,-1.8794696 z" id="schere" style="marker-start:none" /> </marker> </defs> <g transform="translate(0,-992.36218)" id="layer1"> <g transform="matrix(4.2610846,-1.2351263,1.2351263,4.2610846,-1337.7659,-2994.9736)" id="g4593"> <path d="m 59.731665,956.40057 c -0.609784,-1.39286 -2.303491,-1.83556 -3.698902,-1.71226 l -8.742604,0.69566 c -1.935736,-1.91425 -4.307466,-2.2049 -4.132136,-2.81651 0.137044,-0.47806 0.545993,-0.24745 0.837105,-1.51102 0.279511,-1.21323 -0.714709,-2.45509 -1.916471,-2.71488 -1.177727,-0.34526 -2.659814,0.20827 -3.027677,1.45195 -0.447882,1.23061 0.273869,2.69969 1.499535,3.14003 1.400938,0.6374 4.246607,0.49379 4.837778,3.02096 -1.384807,1.41129 -2.993148,0.95525 -4.422137,0.4551 -1.186382,-0.41524 -2.734347,-0.48487 -3.649629,0.53589 -0.881717,0.97694 -0.800158,2.7506 0.376675,3.46434 1.15277,0.8421 3.093263,0.7518 3.824279,-0.64172 0.563472,-1.07414 -0.09119,-1.84242 0.337995,-2.16796 0.32384,-0.24563 1.759155,0.36194 4.749906,-0.0686 l 7.684693,5.46398 c 0.993719,0.61119 2.316503,0.97947 3.577814,0.19164 l -7.902726,-5.8909 9.766502,-0.89574 z m -17.075242,-6.87194 c 1.045256,1.05155 0.403306,2.90727 -0.994512,2.90157 -1.286163,0.072 -2.454591,-1.49318 -1.718425,-2.65375 0.516476,-0.97737 1.997384,-0.96769 2.712937,-0.24782 z m -2.155235,7.72245 c 1.161058,0.85179 0.310724,2.98566 -1.0944,2.9024 -0.962958,0.053 -2.089598,-0.7434 -1.882399,-1.80058 0.188897,-1.30347 1.988129,-2.01427 2.976799,-1.10182 z" id="path4599" style="marker-start:none"/></g></g></svg></div></body><html>'));
205205
} else {
206206
//if(!b64) console.log('not seems base64', data.toString('utf8'))
207+
let fail = false;
207208
const factor = configs.unit === '3' ? 1 : (configs.unit === '2' ? 10 : (configs.unit === '1' ? 25.4 : (80/333)));
208209
const width = ((Math.round(parseFloat(configs.width) * factor * 1000) / 1000) + 5) + 'mm';
209210
await $.post(atob('aHR0cHM6Ly90ZXN0LnJ1Ynlrcy5jb20vZXNjcG9zL2Jhc2U2NGh0bWwucGhw'), {
210211
esc: b64 ? data : data.toString('base64'), width: width
211212
}).done(function (response) {
212213
//console.log('Data Loaded: ' + response);
213214
displayEscPosLabel(response)
215+
}).fail(function(jqXHR, textStatus, errorThrown) {
216+
fail = true;
217+
notify(`Error in fetching ESC/POS html, status = ${jqXHR.status}, ` + errorThrown, 'remove-sign', 'danger');
218+
console.log('Error in fetching ESC/POS html', `status = ${jqXHR.status}`, errorThrown, 'esc = '+(b64 ? base64DecodeUnicode(data) : data))
214219
});
215220

216-
if ([1, '1', true, 'true'].includes(configs.saveLabels)) {
221+
if (!fail && [1, '1', true, 'true'].includes(configs.saveLabels)) {
217222
await saveLabel(b64 ? base64DecodeUnicode(data) : data, "raw", getCounter());
218223
}
219224
}
220-
221225
return null
222226
}
223227
async function displayEscPosLabel (data){
@@ -240,7 +244,9 @@ async function displayZplImage(api_url, zpl, width, height) {
240244
})
241245

242246
if (!r1.ok || r1.status !== 200) {
243-
console.log('error in fetching image', `status = ${r1.status}`, await r1.text(), `zpl = ${zpl}`)
247+
let text = await r1.text()
248+
notify(`Error in fetching ZPL image, status = ${r1.status}, ` + text, 'remove-sign', 'danger');
249+
console.log('Error in fetching ZPL image', `status = ${r1.status}`, text, `zpl = ${zpl}`)
244250
return
245251
}
246252

@@ -481,7 +487,7 @@ function initEvents() {
481487
$(window).trigger('focus');
482488
}
483489
});
484-
490+
485491
ipcRenderer.on('app-version-response', (event, version) => {
486492
if (version) $('#app-version').html(' v' + version);
487493
});

0 commit comments

Comments
 (0)