📅  最后修改于: 2022-03-11 14:48:22.951000             🧑  作者: Mango
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
}
}
}