Answers for "Nestjs Monogdb Handel Catch Error"

0

Nestjs Monogdb Handel Catch Error

import { ArgumentsHost, Catch, ConflictException, ExceptionFilter } from '@nestjs/common';
import { MongoError } from 'mongodb';

@Catch(MongoError)
export class MongoExceptionFilter implements ExceptionFilter {
  catch(exception: MongoError, host: ArgumentsHost) {
    switch (exception.code) {
      case 11000:
        // duplicate exception
        // do whatever you want here, for instance send error to client
    }
  }
}
Posted by: Guest on September-26-2021

Code answers related to "TypeScript"

Browse Popular Code Answers by Language