Skip to content

Commit

Permalink
use custom error
Browse files Browse the repository at this point in the history
  • Loading branch information
Blankll committed Aug 5, 2023
1 parent 0952e2f commit a7c73f2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
1 change: 0 additions & 1 deletion components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export {}
declare module 'vue' {
export interface GlobalComponents {
AppProvider: typeof import('./src/components/AppProvider.vue')['default']
NAlert: typeof import('naive-ui')['NAlert']
NButton: typeof import('naive-ui')['NButton']
NCard: typeof import('naive-ui')['NCard']
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
Expand Down
8 changes: 8 additions & 0 deletions src/common/customError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export class CustomError extends Error {
constructor(
public readonly status: number,
public readonly details: string,
) {
super();
}
}
8 changes: 5 additions & 3 deletions src/views/connect/components/add-dialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@

<script setup lang="ts">
import { Close } from '@vicons/carbon';
import { CustomError } from '../../../common/customError';
const showModal = ref(false);
const modalTitle = ref('添加连接');
Expand Down Expand Up @@ -124,10 +125,11 @@ const testConnect = async () => {
const result = await fetch(`${formOriginData.value.host}:${formOriginData.value.port}`, {
method: 'GET',
});
if (!result.ok) throw { status: result.status, message: await result.json() };
if (!result.ok) new CustomError(result.status, await result.json());
message.success('connect success');
} catch (error) {
message.error(`status: ${error.status}, details: ${error.message}`, {
} catch (e) {
const error = e as CustomError;
message.error(`status: ${error.status}, details: ${error.details}`, {
closable: true,
keepAliveOnHover: true,
duration: 36000000,
Expand Down

0 comments on commit a7c73f2

Please sign in to comment.