nestjs monogdb handel catch error

Solutions on MaxInterview for nestjs monogdb handel catch error by the best coders in the world

showing results for - "nestjs monogdb handel catch error"
Thiago
12 Oct 2020
1import { ArgumentsHost, Catch, ConflictException, ExceptionFilter } from '@nestjs/common';
2import { MongoError } from 'mongodb';
3
4@Catch(MongoError)
5export class MongoExceptionFilter implements ExceptionFilter {
6  catch(exception: MongoError, host: ArgumentsHost) {
7    switch (exception.code) {
8      case 11000:
9        // duplicate exception
10        // do whatever you want here, for instance send error to client
11    }
12  }
13}
14
similar questions
queries leading to this page
nestjs monogdb handel catch error