|
|
@@ -27,6 +27,7 @@ export class HttpExceptionFilter implements ExceptionFilter {
|
|
|
exception instanceof HttpException ? exception.getResponse() : null;
|
|
|
|
|
|
let message: string;
|
|
|
+ let code: string;
|
|
|
if (typeof exceptionResponse === 'object' && exceptionResponse !== null) {
|
|
|
const responseObj = exceptionResponse as any;
|
|
|
if (Array.isArray(responseObj.message)) {
|
|
|
@@ -36,17 +37,20 @@ export class HttpExceptionFilter implements ExceptionFilter {
|
|
|
} else {
|
|
|
message = (exception as Error).message || 'Unknown error';
|
|
|
}
|
|
|
+ // Extract custom code if provided in exception
|
|
|
+ code = responseObj.code || this.mapStatusToCode(status);
|
|
|
} else {
|
|
|
message =
|
|
|
exception instanceof Error
|
|
|
? exception.message
|
|
|
: 'Internal server error';
|
|
|
+ code = this.mapStatusToCode(status);
|
|
|
}
|
|
|
|
|
|
const apiResponse: ApiResponse<null> = {
|
|
|
error: message,
|
|
|
status: 0,
|
|
|
- code: this.mapStatusToCode(status),
|
|
|
+ code,
|
|
|
data: null,
|
|
|
timestamp: new Date().toISOString(),
|
|
|
};
|
|
|
@@ -63,7 +67,7 @@ export class HttpExceptionFilter implements ExceptionFilter {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- response.status(status).send(apiResponse);
|
|
|
+ response.status(200).send(apiResponse);
|
|
|
}
|
|
|
|
|
|
private mapStatusToCode(status: number): string {
|