Refactor code structure for improved readability and maintainability
This commit is contained in:
12
package.json
12
package.json
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/package",
|
||||
"name": "@kevisual/router",
|
||||
"version": "0.0.80",
|
||||
"version": "0.0.81",
|
||||
"description": "",
|
||||
"type": "module",
|
||||
"main": "./dist/router.js",
|
||||
@@ -23,21 +23,21 @@
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@kevisual/code-builder": "^0.0.6",
|
||||
"@kevisual/context": "^0.0.6",
|
||||
"@kevisual/context": "^0.0.8",
|
||||
"@kevisual/dts": "^0.0.4",
|
||||
"@kevisual/js-filter": "^0.0.5",
|
||||
"@kevisual/local-proxy": "^0.0.8",
|
||||
"@kevisual/query": "^0.0.47",
|
||||
"@kevisual/query": "^0.0.49",
|
||||
"@kevisual/use-config": "^1.0.30",
|
||||
"@opencode-ai/plugin": "^1.2.6",
|
||||
"@opencode-ai/plugin": "^1.2.10",
|
||||
"@types/bun": "^1.3.9",
|
||||
"@types/node": "^25.2.3",
|
||||
"@types/node": "^25.3.0",
|
||||
"@types/send": "^1.2.1",
|
||||
"@types/ws": "^8.18.1",
|
||||
"@types/xml2js": "^0.4.14",
|
||||
"eventemitter3": "^5.0.4",
|
||||
"fast-glob": "^3.3.3",
|
||||
"hono": "^4.11.9",
|
||||
"hono": "^4.12.0",
|
||||
"nanoid": "^5.1.6",
|
||||
"path-to-regexp": "^8.3.0",
|
||||
"send": "^1.2.1",
|
||||
|
||||
1203
pnpm-lock.yaml
generated
Normal file
1203
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,20 +1,21 @@
|
||||
type CustomErrorOptions = {
|
||||
cause?: Error | string;
|
||||
code?: number;
|
||||
message?: string;
|
||||
}
|
||||
/** 自定义错误 */
|
||||
export class CustomError extends Error {
|
||||
code?: number;
|
||||
data?: any;
|
||||
message: string;
|
||||
tips?: string;
|
||||
constructor(code?: number | string, message?: string, tips?: string) {
|
||||
super(message || String(code));
|
||||
this.name = 'CustomError';
|
||||
if (typeof code === 'number') {
|
||||
this.code = code;
|
||||
this.message = message!;
|
||||
} else {
|
||||
this.code = 500;
|
||||
this.message = code!;
|
||||
}
|
||||
this.tips = tips;
|
||||
constructor(code?: number | string, opts?: CustomErrorOptions) {
|
||||
let message = opts?.message || String(code);
|
||||
const cause = opts?.cause;
|
||||
super(message, { cause });
|
||||
this.name = 'RouterError';
|
||||
let codeNum = opts?.code || (typeof code === 'number' ? code : undefined);
|
||||
this.code = codeNum ?? 500;
|
||||
this.message = message!;
|
||||
// 这一步可不写,默认会保存堆栈追踪信息到自定义错误构造函数之前,
|
||||
// 而如果写成 `Error.captureStackTrace(this)` 则自定义错误的构造函数也会被保存到堆栈追踪信息
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
@@ -31,8 +32,7 @@ export class CustomError extends Error {
|
||||
return {
|
||||
code: e?.code,
|
||||
data: e?.data,
|
||||
message: e?.message,
|
||||
tips: e?.tips,
|
||||
message: e?.message
|
||||
};
|
||||
}
|
||||
/**
|
||||
@@ -52,7 +52,6 @@ export class CustomError extends Error {
|
||||
code: e?.code,
|
||||
data: e?.data,
|
||||
message: e?.message,
|
||||
tips: e?.tips,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user