Manage errors on webcam better
This commit is contained in:
1 parent
eaa591d93a
commit
d682a18707
2 files changed
+14
-7
No files matched your search
+14
-6
@@ -198,10 +198,11 @@ function setup_events(){
|
||||
const data = await take_picture();
|
||||
|
||||
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) {
|
||||
console.error("Print failed:", e);
|
||||
alert(`Failed to print: ${e.message || e}`);
|
||||
@@ -241,7 +242,8 @@ function take_picture() {
|
||||
const w = video.videoWidth;
|
||||
const h = video.videoHeight;
|
||||
if (!w || !h) {
|
||||
throw new Error(`Invalid video dimensions: ${w} × ${h}`);
|
||||
console.log(`Invalid video dimensions: ${w} × ${h}`);
|
||||
return null;
|
||||
}
|
||||
|
||||
canvas.width = w;
|
||||
@@ -252,7 +254,8 @@ function take_picture() {
|
||||
console.log("Captured image:", data.slice(0, 30), "length:", data.length);
|
||||
|
||||
if (data.length < 100) {
|
||||
throw new Error("Captured image is empty");
|
||||
console.log("Captured image is empty");
|
||||
return null
|
||||
}
|
||||
return data;
|
||||
}
|
||||
@@ -272,10 +275,15 @@ async function print_picture(data) {
|
||||
formData.set("cut", true);
|
||||
formData.set("process", false);
|
||||
|
||||
fetch("/api/print/img", {
|
||||
const res = await fetch("/api/print/img", {
|
||||
method: "POST",
|
||||
body: formData
|
||||
});
|
||||
if(!res.ok){
|
||||
throw new Error("Printing failed" + res.statusText);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function flip_cameras(){
|
||||
|
||||
Reference in new issue
Block a user