diff --git a/web/src/apiClient.ts b/web/src/apiClient.ts index 3962b55..822e069 100644 --- a/web/src/apiClient.ts +++ b/web/src/apiClient.ts @@ -331,7 +331,7 @@ const APIClient = { if (guard(response.data)) { return response.data; } - throw "Unexpected response, types mismatch"; + throw new Error("Unexpected response, types mismatch"); }, }; diff --git a/web/src/components/CTFWizardDialog.vue b/web/src/components/CTFWizardDialog.vue index de8f337..92ac250 100644 --- a/web/src/components/CTFWizardDialog.vue +++ b/web/src/components/CTFWizardDialog.vue @@ -167,10 +167,10 @@ function createService() { service_by_port_loading.value = false; EventBus.emit("showMessage", `Service ${serviceName.value} created.`); }) - .catch((err: string) => { + .catch((err: Error) => { service_by_port_error.value = true; service_by_port_loading.value = false; - EventBus.emit("showError", err); + EventBus.emit("showError", err.message); }); } @@ -192,15 +192,15 @@ function createFlagTags() { .then((res) => { const rejected = res.filter((r) => r.status === "rejected"); if (rejected.length != 0) { - throw rejected.map((r) => r.reason as string).join("; "); + throw new Error(rejected.map((r) => r.reason as string).join("; ")); } visible.value = false; flag_regex_loading.value = false; }) - .catch((err: string) => { + .catch((err: Error) => { flag_regex_error.value = true; flag_regex_loading.value = false; - EventBus.emit("showError", err); + EventBus.emit("showError", err.message); }); } diff --git a/web/src/components/ConverterResetDialog.vue b/web/src/components/ConverterResetDialog.vue index fcd1d87..f988721 100644 --- a/web/src/components/ConverterResetDialog.vue +++ b/web/src/components/ConverterResetDialog.vue @@ -61,10 +61,10 @@ function resetConverterAction() { .then(() => { visible.value = false; }) - .catch((err: string) => { + .catch((err: Error) => { error.value = true; loading.value = false; - EventBus.emit("showError", err); + EventBus.emit("showError", err.message); }); } diff --git a/web/src/components/Converters.vue b/web/src/components/Converters.vue index ccb2902..a3db3e1 100644 --- a/web/src/components/Converters.vue +++ b/web/src/components/Converters.vue @@ -143,11 +143,11 @@ onMounted(() => { }); function refreshConverters() { - store.updateTags().catch((err: string) => { - EventBus.emit("showError", `Failed to update tags: ${err}`); + store.updateTags().catch((err: Error) => { + EventBus.emit("showError", `Failed to update tags: ${err.message}`); }); - store.updateConverters().catch((err: string) => { - EventBus.emit("showError", `Failed to update converters: ${err}`); + store.updateConverters().catch((err: Error) => { + EventBus.emit("showError", `Failed to update converters: ${err.message}`); }); } @@ -170,8 +170,8 @@ function showErrorLog(process: ProcessStats, converter: ConverterStatistics) { fetchStderrError.value = "Stderr is empty"; } }) - .catch((err: string | Error) => { - fetchStderrError.value = err.toString(); + .catch((err: Error) => { + fetchStderrError.value = err.message; }) .finally(() => { loadingStderr.value = false; diff --git a/web/src/components/Graph.vue b/web/src/components/Graph.vue index 19885f0..3e6b85d 100644 --- a/web/src/components/Graph.vue +++ b/web/src/components/Graph.vue @@ -668,8 +668,8 @@ graphStore.$subscribe((_mutation, state) => { theme: colorscheme, }, } as ApexCharts.ApexOptions) - .catch((err: string) => { - EventBus.emit("showError", `Failed to update graph: ${err}`); + .catch((err: Error) => { + EventBus.emit("showError", `Failed to update graph: ${err.message}`); }); }); chartData.value = []; @@ -716,8 +716,8 @@ function fetchGraphLocal() { query as string, type as GraphType, ) - .catch((err: string) => { - EventBus.emit("showError", `Failed to update graph: ${err}`); + .catch((err: Error) => { + EventBus.emit("showError", `Failed to update graph: ${err.message}`); }); } diff --git a/web/src/components/Navigation.vue b/web/src/components/Navigation.vue index d7e6039..6e00753 100644 --- a/web/src/components/Navigation.vue +++ b/web/src/components/Navigation.vue @@ -318,11 +318,11 @@ onMounted(() => { .then(() => { if (store.tags?.length === 0) EventBus.emit("showCTFWizard"); }) - .catch((err: string) => { - EventBus.emit("showError", `Failed to update tags: ${err}`); + .catch((err: Error) => { + EventBus.emit("showError", `Failed to update tags: ${err.message}`); }); - store.updateStatus().catch((err: string) => { - EventBus.emit("showError", `Failed to update status: ${err}`); + store.updateStatus().catch((err: Error) => { + EventBus.emit("showError", `Failed to update status: ${err.message}`); }); }); diff --git a/web/src/components/PcapOverIP.vue b/web/src/components/PcapOverIP.vue index 6e48f74..7c9e53c 100644 --- a/web/src/components/PcapOverIP.vue +++ b/web/src/components/PcapOverIP.vue @@ -205,10 +205,10 @@ onMounted(() => { }); function refresh() { - store.updatePcapOverIPEndpoints().catch((err: string) => { + store.updatePcapOverIPEndpoints().catch((err: Error) => { EventBus.emit( "showError", - `Failed to update PCAP-over-IP endpoints: ${err}`, + `Failed to update PCAP-over-IP endpoints: ${err.message}`, ); }); } @@ -224,10 +224,13 @@ function add() { newAddress.value = ""; refresh(); }) - .catch((err: string) => { + .catch((err: Error) => { addDialogLoading.value = false; addDialogError.value = true; - EventBus.emit("showError", `Failed to add PCAP-over-IP endpoint: ${err}`); + EventBus.emit( + "showError", + `Failed to add PCAP-over-IP endpoint: ${err.message}`, + ); }); } function del() { @@ -240,10 +243,10 @@ function del() { delDialogLoading.value = false; refresh(); }) - .catch((err: string) => { + .catch((err: Error) => { EventBus.emit( "showError", - `Failed to delete PCAP-over-IP endpoint: ${err}`, + `Failed to delete PCAP-over-IP endpoint: ${err.message}`, ); delDialogError.value = true; delDialogLoading.value = false; diff --git a/web/src/components/Pcaps.vue b/web/src/components/Pcaps.vue index 61a4181..0675630 100644 --- a/web/src/components/Pcaps.vue +++ b/web/src/components/Pcaps.vue @@ -86,8 +86,8 @@ const headers = [ ]; onMounted(() => { - store.updatePcaps().catch((err: string) => { - EventBus.emit("showError", `Failed to update pcaps: ${err}`); + store.updatePcaps().catch((err: Error) => { + EventBus.emit("showError", `Failed to update pcaps: ${err.message}`); }); }); diff --git a/web/src/components/Results.vue b/web/src/components/Results.vue index 36bce81..127f7e1 100644 --- a/web/src/components/Results.vue +++ b/web/src/components/Results.vue @@ -422,8 +422,8 @@ function fetchStreams(forceUpdate = false) { return; } - streams.searchStreams(query, page).catch((err: string) => { - EventBus.emit("showError", `Failed to fetch streams: ${err}`); + streams.searchStreams(query, page).catch((err: Error) => { + EventBus.emit("showError", `Failed to fetch streams: ${err.message}`); }); selected.value = []; } @@ -441,12 +441,18 @@ function markSelectedStreams(tagId: string, value: boolean) { ids.push(s.Stream.ID); } if (value) - store.markTagAdd(tagId, ids).catch((err: string) => { - EventBus.emit("showError", `Failed to add streams to tag: ${err}`); + store.markTagAdd(tagId, ids).catch((err: Error) => { + EventBus.emit( + "showError", + `Failed to add streams to tag: ${err.message}`, + ); }); else - store.markTagDel(tagId, ids).catch((err: string) => { - EventBus.emit("showError", `Failed to remove streams from tag: ${err}`); + store.markTagDel(tagId, ids).catch((err: Error) => { + EventBus.emit( + "showError", + `Failed to remove streams from tag: ${err.message}`, + ); }); } diff --git a/web/src/components/SearchBox.vue b/web/src/components/SearchBox.vue index a5ec0e0..9bcb143 100644 --- a/web/src/components/SearchBox.vue +++ b/web/src/components/SearchBox.vue @@ -215,8 +215,8 @@ watch( ); onMounted(() => { - store.updateConverters().catch((err: string) => { - EventBus.emit("showError", `Failed to update converters: ${err}`); + store.updateConverters().catch((err: Error) => { + EventBus.emit("showError", `Failed to update converters: ${err.message}`); }); const keyListener = (e: KeyboardEvent) => { if (e.target === null || !(e.target instanceof Element)) return; diff --git a/web/src/components/Status.vue b/web/src/components/Status.vue index 286def0..0469bba 100644 --- a/web/src/components/Status.vue +++ b/web/src/components/Status.vue @@ -37,8 +37,8 @@ onMounted(() => { }); function updateStatus() { - store.updateStatus().catch((err: string) => { - EventBus.emit("showError", `Failed to update status: ${err}`); + store.updateStatus().catch((err: Error) => { + EventBus.emit("showError", `Failed to update status: ${err.message}`); }); } diff --git a/web/src/components/Stream.vue b/web/src/components/Stream.vue index 0b95c83..438f289 100644 --- a/web/src/components/Stream.vue +++ b/web/src/components/Stream.vue @@ -535,8 +535,8 @@ function changeConverter(converter: string) { function fetchStreamForId() { if (streamId.value !== null) { - stream.fetchStream(streamId.value, converter.value).catch((err: string) => { - EventBus.emit("showError", `Failed to fetch stream: ${err}`); + stream.fetchStream(streamId.value, converter.value).catch((err: Error) => { + EventBus.emit("showError", `Failed to fetch stream: ${err.message}`); }); document.getSelection()?.empty(); } @@ -559,12 +559,18 @@ function createMark() { function markStream(tagId: string, value: boolean) { if (value) { - store.markTagAdd(tagId, [streamId.value]).catch((err: string) => { - EventBus.emit("showError", `Failed to add stream to mark: ${err}`); + store.markTagAdd(tagId, [streamId.value]).catch((err: Error) => { + EventBus.emit( + "showError", + `Failed to add stream to mark: ${err.message}`, + ); }); } else { - store.markTagDel(tagId, [streamId.value]).catch((err: string) => { - EventBus.emit("showError", `Failed to remove stream from mark: ${err}`); + store.markTagDel(tagId, [streamId.value]).catch((err: Error) => { + EventBus.emit( + "showError", + `Failed to remove stream from mark: ${err.message}`, + ); }); } } diff --git a/web/src/components/StreamData.vue b/web/src/components/StreamData.vue index 7c42ce2..fe8fe5f 100644 --- a/web/src/components/StreamData.vue +++ b/web/src/components/StreamData.vue @@ -66,7 +66,7 @@ const highlightRegex = (highlight: string[] | null) => return decoded; }); return new RegExp(regex, "g"); - } catch (e) { + } catch { console.error(`Invalid regex: ${regex}`); } }); diff --git a/web/src/components/TagColorChangeDialog.vue b/web/src/components/TagColorChangeDialog.vue index 465ae70..c640f8b 100644 --- a/web/src/components/TagColorChangeDialog.vue +++ b/web/src/components/TagColorChangeDialog.vue @@ -120,10 +120,10 @@ function updateColor() { .then(() => { visible.value = false; }) - .catch((err: string) => { + .catch((err: Error) => { error.value = true; loading.value = false; - EventBus.emit("showError", err); + EventBus.emit("showError", err.message); }); } diff --git a/web/src/components/TagCreateDialog.vue b/web/src/components/TagCreateDialog.vue index c873c0c..d7e28de 100644 --- a/web/src/components/TagCreateDialog.vue +++ b/web/src/components/TagCreateDialog.vue @@ -129,10 +129,10 @@ function createTag() { .then(() => { visible.value = false; }) - .catch((err: string) => { + .catch((err: Error) => { error.value = true; loading.value = false; - EventBus.emit("showError", err); + EventBus.emit("showError", err.message); }); } diff --git a/web/src/components/TagDefinitionChangeDialog.vue b/web/src/components/TagDefinitionChangeDialog.vue index 777349d..9f0ac86 100644 --- a/web/src/components/TagDefinitionChangeDialog.vue +++ b/web/src/components/TagDefinitionChangeDialog.vue @@ -72,10 +72,10 @@ function updateDefinition() { .then(() => { visible.value = false; }) - .catch((err: string) => { + .catch((err: Error) => { error.value = true; loading.value = false; - EventBus.emit("showError", err); + EventBus.emit("showError", err.message); }); } diff --git a/web/src/components/TagDeleteDialog.vue b/web/src/components/TagDeleteDialog.vue index 1d17aa0..e1d574e 100644 --- a/web/src/components/TagDeleteDialog.vue +++ b/web/src/components/TagDeleteDialog.vue @@ -62,10 +62,10 @@ function deleteTag() { .then(() => { visible.value = false; }) - .catch((err: string) => { + .catch((err: Error) => { error.value = true; loading.value = false; - EventBus.emit("showError", err); + EventBus.emit("showError", err.message); }); } diff --git a/web/src/components/TagNameChangeDialog.vue b/web/src/components/TagNameChangeDialog.vue index 57681a1..14d1fed 100644 --- a/web/src/components/TagNameChangeDialog.vue +++ b/web/src/components/TagNameChangeDialog.vue @@ -72,10 +72,10 @@ function updateName() { .then(() => { visible.value = false; }) - .catch((err: string) => { + .catch((err: Error) => { error.value = true; loading.value = false; - EventBus.emit("showError", err); + EventBus.emit("showError", err.message); }); } diff --git a/web/src/components/TagSetConverterDialog.vue b/web/src/components/TagSetConverterDialog.vue index 4b28493..7c060b1 100644 --- a/web/src/components/TagSetConverterDialog.vue +++ b/web/src/components/TagSetConverterDialog.vue @@ -88,10 +88,10 @@ function submitTagConverters() { .then(() => { visible.value = false; }) - .catch((err: string) => { + .catch((err: Error) => { error.value = true; loading.value = false; - EventBus.emit("showError", err); + EventBus.emit("showError", err.message); }); } diff --git a/web/src/components/Tags.vue b/web/src/components/Tags.vue index 40c51aa..d2a78b2 100644 --- a/web/src/components/Tags.vue +++ b/web/src/components/Tags.vue @@ -206,8 +206,8 @@ onMounted(() => { }); function updateTags() { - store.updateTags().catch((err: string) => { - EventBus.emit("showError", `Failed to update tags: ${err}`); + store.updateTags().catch((err: Error) => { + EventBus.emit("showError", `Failed to update tags: ${err.message}`); }); } diff --git a/web/src/stores/graph.ts b/web/src/stores/graph.ts index 51a70b9..55f4a2d 100644 --- a/web/src/stores/graph.ts +++ b/web/src/stores/graph.ts @@ -61,7 +61,7 @@ export const useGraphStore = defineStore("graph", { this.graph = data; this.running = false; }) - .catch((err) => { + .catch((err: unknown) => { if (axios.isCancel(err)) return; if (axios.isAxiosError(err)) { this.delta = delta; diff --git a/web/src/stores/index.ts b/web/src/stores/index.ts index 6dca5e1..9739c08 100644 --- a/web/src/stores/index.ts +++ b/web/src/stores/index.ts @@ -98,11 +98,7 @@ export const useRootStore = defineStore("root", { }, async delPcapOverIPEndpoint(address: string) { return APIClient.delPcapOverIPEndpoint(address) - .then(() => { - this.updatePcapOverIPEndpoints().catch((err) => { - throw err; - }); - }) + .then(() => this.updatePcapOverIPEndpoints()) .catch(handleAxiosDefaultError); }, async updateConverters() { @@ -124,9 +120,7 @@ export const useRootStore = defineStore("root", { return APIClient.delTag(name) .then(() => { this.updateMark(name, undefined, false); - this.updateTags().catch((err) => { - throw err; - }); // TODO: not required with websocket? + return this.updateTags(); // TODO: not required with websocket? }) .catch(handleAxiosDefaultError); }, @@ -159,9 +153,7 @@ export const useRootStore = defineStore("root", { return APIClient.markTagNew(name, streams, color) .then(() => { this.updateMark(name, streams, true); - this.updateTags().catch((err) => { - throw err; - }); // TODO: not required with websocket? + return this.updateTags(); // TODO: not required with websocket? }) .catch(handleAxiosDefaultError); }, @@ -169,9 +161,7 @@ export const useRootStore = defineStore("root", { return APIClient.markTagAdd(name, streams) .then(() => { this.updateMark(name, streams, true); - this.updateTags().catch((err) => { - throw err; - }); // TODO: not required with websocket? + return this.updateTags(); // TODO: not required with websocket? }) .catch(handleAxiosDefaultError); }, @@ -179,9 +169,7 @@ export const useRootStore = defineStore("root", { return APIClient.markTagDel(name, streams) .then(() => { this.updateMark(name, streams, false); - this.updateTags().catch((err) => { - throw err; - }); // TODO: not required with websocket? + return this.updateTags(); // TODO: not required with websocket? }) .catch(handleAxiosDefaultError); }, @@ -190,8 +178,10 @@ export const useRootStore = defineStore("root", { export function handleAxiosDefaultError(err: unknown) { if (axios.isAxiosError(err)) - throw err.response !== undefined && err.response.data !== "" - ? err.response.data - : err.message; + throw new Error( + err.response !== undefined && err.response.data !== "" + ? err.response.data + : err.message, + ); else throw err; } diff --git a/web/src/stores/stream.ts b/web/src/stores/stream.ts index b010498..d56eca1 100644 --- a/web/src/stores/stream.ts +++ b/web/src/stores/stream.ts @@ -30,7 +30,7 @@ export const useStreamStore = defineStore("stream", { this.stream = data; this.running = false; }) - .catch((err) => { + .catch((err: unknown) => { if (axios.isAxiosError(err)) { this.id = id; this.error = diff --git a/web/src/stores/streams.ts b/web/src/stores/streams.ts index 46e539a..c9bbecb 100644 --- a/web/src/stores/streams.ts +++ b/web/src/stores/streams.ts @@ -44,7 +44,7 @@ export const useStreamsStore = defineStore("streams", { this.page = page; this.running = false; }) - .catch((err) => { + .catch((err: unknown) => { if (axios.isCancel(err)) return; if (axios.isAxiosError(err)) { this.query = query;