refactor: clean code

This commit is contained in:
Fu Diwei
2024-12-23 19:31:48 +08:00
parent d509445519
commit 9ef16ebcf9
6 changed files with 21 additions and 9 deletions

View File

@@ -1,3 +1,5 @@
import { ClientResponseError } from "pocketbase";
import { getPocketBase } from "@/repository/pocketbase";
export const notifyTest = async (channel: string) => {
@@ -13,8 +15,8 @@ export const notifyTest = async (channel: string) => {
},
});
if (resp.code != 0) {
throw new Error(resp.msg);
if (resp.status != 0 && resp.status !== 200) {
throw new ClientResponseError({ status: resp.status, response: resp, data: {} });
}
return resp;

View File

@@ -1,4 +1,6 @@
import { Statistics } from "@/domain/statistics";
import { ClientResponseError } from "pocketbase";
import { type Statistics } from "@/domain/statistics";
import { getPocketBase } from "@/repository/pocketbase";
export const get = async () => {
@@ -8,8 +10,8 @@ export const get = async () => {
method: "GET",
});
if (resp.code !== 0) {
throw new Error(resp.msg);
if (resp.status != 0 && resp.status !== 200) {
throw new ClientResponseError({ status: resp.status, response: resp, data: {} });
}
return resp.data as Statistics;

View File

@@ -1,3 +1,5 @@
import { ClientResponseError } from "pocketbase";
import { getPocketBase } from "@/repository/pocketbase";
export const run = async (id: string) => {
@@ -13,8 +15,8 @@ export const run = async (id: string) => {
},
});
if (resp.code != 0) {
throw new Error(resp.msg);
if (resp.status != 0 && resp.status !== 200) {
throw new ClientResponseError({ status: resp.status, response: resp, data: {} });
}
return resp;

View File

@@ -17,6 +17,9 @@ i18n
backend: {
loadPath: "/locales/{{lng}}.json",
},
detection: {
lookupLocalStorage: "certimate-ui-lang",
},
});
export const localeNames = {