Skip to content

Commit 9d8719d

Browse files
committed
fix: response error global
1 parent f36b36b commit 9d8719d

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/middlewares/ExpressErrorResponse.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// eslint-disable-next-line no-unused-vars
22
import { NextFunction, Request, Response } from 'express'
3-
import ResponseError from 'modules/ResponseError'
3+
import ResponseError from 'modules/Response/ResponseError'
44
import { isObject } from 'lodash'
55

6-
function generateErrorResponseError(e: Error) {
7-
return isObject(e.message) ? e.message : { message: e.message }
6+
function generateErrorResponseError(e: Error, code: Number) {
7+
return isObject(e.message) ? e.message : { code, message: e.message }
88
}
99

1010
async function ExpressErrorResponse(
@@ -14,7 +14,9 @@ async function ExpressErrorResponse(
1414
next: NextFunction
1515
) {
1616
if (err instanceof ResponseError.BaseResponse) {
17-
return res.status(err.statusCode).json(generateErrorResponseError(err))
17+
return res
18+
.status(err.statusCode)
19+
.json(generateErrorResponseError(err, err.statusCode))
1820
}
1921

2022
next(err)

0 commit comments

Comments
 (0)