Manage errors on webcam better

This commit is contained in:
n07070 committed 2026-11-18 17:16:35 +01:00
1 parent eaa591d93a
commit d682a18707
2 files changed
+14 -7

No files matched your search

-1
View File
@@ -493,6 +493,5 @@ def camera_status():
else: else:
socketio.emit("camera_status", False) socketio.emit("camera_status", False)
if __name__ == "__main__": if __name__ == "__main__":
app.run(use_reloader=False, host="0.0.0.0", ssl_context="adhoc") app.run(use_reloader=False, host="0.0.0.0", ssl_context="adhoc")
+14 -6
View File
@@ -198,10 +198,11 @@ function setup_events(){
const data = await take_picture(); const data = await take_picture();
if (!data) { if (!data) {
throw new Error("No image was captured"); console.error("Print failed: No image was captured");
} else {
console.log("Printing picture");
const print_status = await print_picture(data);
} }
await print_picture(data);
} catch (e) { } catch (e) {
console.error("Print failed:", e); console.error("Print failed:", e);
alert(`Failed to print: ${e.message || e}`); alert(`Failed to print: ${e.message || e}`);
@@ -241,7 +242,8 @@ function take_picture() {
const w = video.videoWidth; const w = video.videoWidth;
const h = video.videoHeight; const h = video.videoHeight;
if (!w || !h) { if (!w || !h) {
throw new Error(`Invalid video dimensions: ${w} × ${h}`); console.log(`Invalid video dimensions: ${w} × ${h}`);
return null;
} }
canvas.width = w; canvas.width = w;
@@ -252,7 +254,8 @@ function take_picture() {
console.log("Captured image:", data.slice(0, 30), "length:", data.length); console.log("Captured image:", data.slice(0, 30), "length:", data.length);
if (data.length < 100) { if (data.length < 100) {
throw new Error("Captured image is empty"); console.log("Captured image is empty");
return null
} }
return data; return data;
} }
@@ -272,10 +275,15 @@ async function print_picture(data) {
formData.set("cut", true); formData.set("cut", true);
formData.set("process", false); formData.set("process", false);
fetch("/api/print/img", { const res = await fetch("/api/print/img", {
method: "POST", method: "POST",
body: formData body: formData
}); });
if(!res.ok){
throw new Error("Printing failed" + res.statusText);
} else {
return true;
}
} }
function flip_cameras(){ function flip_cameras(){