0

RcpException をフィルタリングしようとしています (問題がある場合は RabbitMQ から)

ゲートウェイ.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' }

フィルタが機能しないのはなぜですか?

4

0 に答える 0