Skip to content

Commit

Permalink
Merge pull request #701 from Cobidex/fix/custom-exception-filter
Browse files Browse the repository at this point in the history
fix: error response format
  • Loading branch information
CFCIfe authored Aug 8, 2024
2 parents fdcda40 + 49f0c07 commit b6c32b0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/helpers/custom-http-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ export class CustomHttpException extends HttpException {

getResponse(): any {
const response = super.getResponse();
const status = this.getStatus();
const status_code = this.getStatus();

if (typeof response === 'object' && response !== null) {
const res = response as Record<string, any>;
return {
message: res.message || 'An error occurred',
status,
status_code,
};
}

return {
message: response,
status,
status_code,
};
}
}
2 changes: 1 addition & 1 deletion src/shared/inteceptors/response.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class ResponseInterceptor implements NestInterceptor {
`Error processing request for ${req.method} ${req.url}, Message: ${exception['message']}, Stack: ${exception['stack']}`
);
return new InternalServerErrorException({
status: HttpStatus.INTERNAL_SERVER_ERROR,
status_code: HttpStatus.INTERNAL_SERVER_ERROR,
message: 'Internal server error',
});
}
Expand Down

0 comments on commit b6c32b0

Please sign in to comment.