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