gateway.ts:
@Get('test-exception')
@HttpCode(HttpStatus.OK)
@UseFilters(RpcExceptionFilter)
async testException() {
try {
return await lastValueFrom(this.testRMQ.send('test', {}));
} catch (error) {
console.log(error);
}
}
rpc-exception-filter.ts:
import { Catch, ExceptionFilter } from "@nestjs/common";
import { RpcException } from "@nestjs/microservices";
@Catch(RpcException)
export class RpcExceptionFilter implements ExceptionFilter {
catch(exception: RpcException) {
const error = exception.getError();
return {staus: 500, error: 'RpcFilterError'};
}
}
testRMQ.ts:
@MessagePattern('test')
updateInstrumentList(@Payload() payload: void, @Ctx() context: RmqContext) {
throw new RpcException('Invalid credentials');
}
Ожидаемый вывод:
{ status: 500, message: 'RpcFilterError' }
Получаемый вывод:
{ status: 'error', message: 'Invalid credentials' }
Почему не отрабатывает фильтр?