From ef3593670f409e7342a6201987f1a294fc9377cf Mon Sep 17 00:00:00 2001 From: ingalls Date: Wed, 18 Sep 2024 16:40:51 -0600 Subject: [PATCH] Gracefully catch errors and show inline --- api/lib/control/video-service.ts | 23 ++++++++ api/web/src/components/CloudTAK/CoTView.vue | 1 + .../src/components/CloudTAK/util/Video.vue | 54 +++++++++++++------ 3 files changed, 61 insertions(+), 17 deletions(-) diff --git a/api/lib/control/video-service.ts b/api/lib/control/video-service.ts index 802aa7c88..f65f7fc78 100644 --- a/api/lib/control/video-service.ts +++ b/api/lib/control/video-service.ts @@ -297,6 +297,29 @@ export default class VideoServiceControl { headers.append('Content-Type', 'application/json'); if (lease.proxy) { + try { + const proxy = new URL(opts.proxy); + + // Check for HLS Errors + if (['http:', 'https:'].includes(proxy.protocol)) { + const res = await fetch(proxy); + + if (res.status === 404) { + throw new Err(400, null, 'External Video Server reports Video Stream not found'); + } else if (!res.ok) { + throw new Err(res.status, null, `External Video Server failed stream video - HTTP Error ${res.status}`); + } + } + } catch (err) { + if (err instanceof Err) { + throw err; + } else if (err instanceof TypeError && err.code === 'ERR_INVALID_URL') { + throw new Err(400, null, 'Invalid Video Stream URL'); + } else { + throw new Err(500, err instanceof Error ? err : new Error(String(err)), 'Failed to generate proxy stream'); + } + } + const res = await fetch(url, { method: 'POST', headers, diff --git a/api/web/src/components/CloudTAK/CoTView.vue b/api/web/src/components/CloudTAK/CoTView.vue index a51c09615..9e0384bb1 100644 --- a/api/web/src/components/CloudTAK/CoTView.vue +++ b/api/web/src/components/CloudTAK/CoTView.vue @@ -287,6 +287,7 @@ diff --git a/api/web/src/components/CloudTAK/util/Video.vue b/api/web/src/components/CloudTAK/util/Video.vue index bd2ce64b0..45a67b17b 100644 --- a/api/web/src/components/CloudTAK/util/Video.vue +++ b/api/web/src/components/CloudTAK/util/Video.vue @@ -1,6 +1,13 @@