Added API

This commit is contained in:
2022-08-26 06:36:45 +07:00
parent 56fbe3109c
commit 96bba465d9
8 changed files with 156 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
import HTTP_STATUS from "../libs/HTTPStatus";
import Logger from "../libs/Logger";
import { ServiceError } from "./Errors";
class ExpressExceptionHandler {
public static errorLogger(error: any, req: any, res: any, next: any) {
if(error instanceof ServiceError) {
res.status(error.statusCode).json({
error: error.message
})
}
else {
res.status(HTTP_STATUS.INTERNAL_SERVER_ERROR).json({
error: "Internal server error"
})
throw error;
}
}
}
export default ExpressExceptionHandler;