Forked from
Eclipse Projects / xfsc / Organization Credential Manager / OCM-Engine
364 commits behind the upstream repository.
-
Konstantin Tsabolov authored
* Upgraded the dependencies to the latest versions * Switched output to ESM format * Switched NestJS and Jest to SWC to improve speed of building and testing * Refactored TSConfig to remove tsconfig-paths * Updated imports in all files to reflect the change in TSConfig * Changed the linting rules (removed AirBnB config) * Fixed Prettier installation (added ignore file) * Fixed typing errors (mainly usage of any's) * Fixed the non-working E2E test P.S. None of the mentioned makes sense alone, therefore a huge commit
Konstantin Tsabolov authored* Upgraded the dependencies to the latest versions * Switched output to ESM format * Switched NestJS and Jest to SWC to improve speed of building and testing * Refactored TSConfig to remove tsconfig-paths * Updated imports in all files to reflect the change in TSConfig * Changed the linting rules (removed AirBnB config) * Fixed Prettier installation (added ignore file) * Fixed typing errors (mainly usage of any's) * Fixed the non-working E2E test P.S. None of the mentioned makes sense alone, therefore a huge commit
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
exception.handler.ts 1.32 KiB
import {
ArgumentsHost,
Catch,
ExceptionFilter,
HttpException,
HttpStatus,
} from '@nestjs/common';
import { HttpAdapterHost } from '@nestjs/core';
import ResponseType from './response.js';
@Catch()
export default class ExceptionHandler implements ExceptionFilter {
constructor(private readonly httpAdapterHost: HttpAdapterHost) {}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
catch(exception: any, host: ArgumentsHost): void {
// In certain situations `httpAdapter` might not be available in the
// constructor method, thus we should resolve it here.
const { httpAdapter } = this.httpAdapterHost;
const ctx = host.switchToHttp();
const response = ctx.getResponse();
let statusCode = HttpStatus.INTERNAL_SERVER_ERROR;
let message =
exception.message.error || exception.message || 'Something went wrong!';
if (exception instanceof HttpException) {
const errorResponse: string | object = exception.getResponse();
statusCode = exception.getStatus();
message =
(typeof errorResponse === 'object' &&
Reflect.get(errorResponse, 'error')) ||
message;
}
const responseBody: ResponseType = {
statusCode,
message,
error: exception.message,
};
httpAdapter.reply(response, responseBody, statusCode);
}
}