@emad-test/monmedx-common
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

commons-service

commons-service

HttpExceptionFilter

to Catch every unhandled exception (regardless of the exception type) and make the response as

{
    errors: [
        feilds: string[],
        messages: string,
        code: string
    ]
}

this Filter handle three types of errors

  • validation errors from the dto level
  • unexpected error
  • validation in the business logic but at this level, you want to handle the structure of the error manually like that
throw new ConflictException({
            fields: ['feild'],
            code: 'CONFLICTS',
            message: 'your message',
          });

How to use it on the nestjs project

  • in the main.ts file, import the module
import { HttpExceptionFilter } from '@mon-medic/common';
  • in the bootstrap function add this line
  app.useGlobalFilters(new HttpExceptionFilter());

Readme

Keywords

none

Package Sidebar

Install

npm i @emad-test/monmedx-common

Weekly Downloads

0

Version

1.0.4

License

ISC

Unpacked Size

173 kB

Total Files

199

Last publish

Collaborators

  • emad-darabeh