diff --git a/common/ApiError.ts b/common/ApiError.ts index ff48b6d..fb5a81e 100644 --- a/common/ApiError.ts +++ b/common/ApiError.ts @@ -25,6 +25,7 @@ export default class ApiError extends Error { toJSON(development: boolean = false) { return { message: this.message, + statusCode: this.statusCode, code: this.code, data: development ? this.data : undefined }; diff --git a/server/express/errorHandler.ts b/server/express/errorHandler.ts index cadc244..7a8d55b 100644 --- a/server/express/errorHandler.ts +++ b/server/express/errorHandler.ts @@ -14,13 +14,15 @@ const errorHandler: express.ErrorRequestHandler = ( if (err instanceof ApiError) { // TODO: different content-type? res.status(err.statusCode).json(err.toJSON(isDev)); - } else { + } else if (err) { const internalError = new ApiError( "An internal server error has occurred", - ErrorCode.Internal + ErrorCode.Internal, + err.stack ? err.stack : err ); errorHandler(internalError, req, res, next); } + next(); }; export default errorHandler;