import { HttpException, HttpStatus } from '@nestjs/common';

export class MTypeErrorHandler {
  static handleException = function (ex: Error): void {
    throw new HttpException(
      {
        statusCode: HttpStatus.INTERNAL_SERVER_ERROR,
        timestamp: new Date().toISOString(),
        message: 'Unexpected exception occurred - MT Service' + ex.message,
        trace: ex.stack,
      },
      HttpStatus.INTERNAL_SERVER_ERROR,
    );
  };

  static handleRejectedPromise = function (
    reason: any,
    promise: Promise<any>,
  ): void {
    throw new HttpException(
      {
        statusCode: HttpStatus.INTERNAL_SERVER_ERROR,
        timestamp: new Date().toISOString(),
        message:
          'Unhandled rejection of promise - MT Service - ' + reason.message,
        trace: promise,
      },
      HttpStatus.INTERNAL_SERVER_ERROR,
    );
  };
}
