Skip to content

Commit

Permalink
chore: move error notification function to utils.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
D-D-H committed Mar 11, 2024
1 parent 0f967f4 commit 230ecc6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
10 changes: 2 additions & 8 deletions frontend/src/composables/analysis-api-requester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
import type { FileType } from '@/composables/file-types';
import { useAnalysisStore } from '@/stores/analysis';
import { useEnv } from '@/stores/env';
import { showErrorNotification } from '@/support/utils';
import { Client } from '@stomp/stompjs';
import axios from 'axios';
import { ElNotification } from 'element-plus';
// @ts-ignore
import { v4 as uuidv4 } from 'uuid';

Expand Down Expand Up @@ -97,13 +97,7 @@ function byStomp(resolve: (req: Requester) => void) {
}

resRejMap.delete(requestId);
ElNotification.error({
title: data.errorCode,
message: data.message,
offset: 80,
duration: 0,
showClose: true
});
showErrorNotification(data.errorCode, data.message);
resRej.reject(data);
}
}
Expand Down
11 changes: 2 additions & 9 deletions frontend/src/stores/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
import { useAnalysisStore } from '@/stores/analysis';
import { showErrorNotification } from '@/support/utils';
import axios from 'axios';
import axiosRetry from 'axios-retry';
import { ElNotification } from 'element-plus';
import { defineStore } from 'pinia';
// @ts-ignore
import Cookies from 'js-cookie';
import { h } from 'vue';

export interface User {
name: string;
Expand Down Expand Up @@ -150,13 +149,7 @@ axios.interceptors.response.use(
let data = resp.data;
if (status === 500) {
if (data && data.hasOwnProperty('errorCode')) {
ElNotification.error({
title: data.errorCode,
message: h('p', { style: 'word-break: break-all' }, data.message),
offset: 50,
duration: 0,
showClose: true
});
showErrorNotification(data.errorCode, data.message);
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/support/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
import { formatDate } from '@vueuse/core';
import { ElNotification } from 'element-plus';
import { h } from 'vue';

function nullOrUndefined(v: any) {
return v === null || v === undefined;
Expand Down Expand Up @@ -76,3 +78,13 @@ export function prettyTime(number: number, format: string) {
}
return format;
}

export function showErrorNotification(errorCode: string, message: string) {
ElNotification.error({
title: errorCode,
message: h('p', { style: 'word-break: break-all' }, message),
offset: 50,
duration: 0,
showClose: true
});
}

0 comments on commit 230ecc6

Please sign in to comment.