Skip to content

Commit

Permalink
feat: add config
Browse files Browse the repository at this point in the history
  • Loading branch information
lizhen committed Aug 23, 2022
1 parent 0c2f12e commit 2b0de52
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
27 changes: 27 additions & 0 deletions lib/decorator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,36 @@ export const defaultErrorWrapper = (error: any): ResponseData<any> => {
return {
success: false,
errorMessage: error.message,
errorCode: error.code,
};
};

export type ResponseErrorProps =
| string
| {
message: string;
code?: string;
error?: Error;
};
export class ResponseError implements Error {
name: string = 'ResponseError';
stack?: string;
message: string;
code?: string;
constructor(props: ResponseErrorProps) {
if (typeof props === 'string') {
this.message = props;
} else {
this.message = props.message;
this.code = props.code;
this.stack = props.error?.stack;
}
}
public toString() {
return `${this.name}${this.code ? `(code:${this.code})` : ''}: ${this.message}`;
}
}

export type ResponseJsonOptions = {
/**
* 用来转换返回的结果对象到标准的json
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "egg-fancy-decorator",
"version": "1.0.4",
"version": "1.0.5",
"description": "Decorator support plugin for egg framework",
"main": "lib/index.js",
"types": "index.d.ts",
Expand Down

0 comments on commit 2b0de52

Please sign in to comment.