14 lines
469 B
TypeScript
14 lines
469 B
TypeScript
|
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:
|
||
|
console.log('llave duplicada')
|
||
|
// duplicate exception
|
||
|
// do whatever you want here, for instance send error to client
|
||
|
}
|
||
|
}
|
||
|
}
|