fix: change dev message to code
This commit is contained in:
parent
ddec8275d8
commit
9722fab149
2 changed files with 6 additions and 15 deletions
|
|
@ -1,29 +1,20 @@
|
|||
import HttpStatus from "./http-status";
|
||||
|
||||
type DevMessage =
|
||||
| "missing_or_invalid_parameter"
|
||||
| "data_exists"
|
||||
| "data_in_used"
|
||||
| "no_permission"
|
||||
| "unknown_url"
|
||||
| "data_not_found"
|
||||
| "unauthorized";
|
||||
|
||||
class HttpError extends Error {
|
||||
/**
|
||||
* HTTP Status Code
|
||||
*/
|
||||
status: HttpStatus;
|
||||
message: string;
|
||||
devMessage?: DevMessage;
|
||||
code?: string;
|
||||
|
||||
constructor(status: HttpStatus, message: string, devMessage?: DevMessage) {
|
||||
constructor(status: HttpStatus, message: string, code?: string) {
|
||||
super(message);
|
||||
|
||||
this.name = "HttpError";
|
||||
this.status = status;
|
||||
this.message = message;
|
||||
this.devMessage = devMessage;
|
||||
this.code = code;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ function error(error: Error, _req: Request, res: Response, _next: NextFunction)
|
|||
return res.status(error.status).json({
|
||||
status: error.status,
|
||||
message: error.message,
|
||||
devMessage: error.devMessage,
|
||||
code: error.code,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -17,7 +17,7 @@ function error(error: Error, _req: Request, res: Response, _next: NextFunction)
|
|||
status: HttpStatus.UNPROCESSABLE_ENTITY,
|
||||
message: "Validation error(s).",
|
||||
detail: error.fields,
|
||||
devMessage: "missing_or_invalid_parameter",
|
||||
code: "validateError",
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -26,7 +26,7 @@ function error(error: Error, _req: Request, res: Response, _next: NextFunction)
|
|||
return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json({
|
||||
status: HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
message: error.message,
|
||||
devMessage: "system_error",
|
||||
code: "system_error",
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue