RpcException does not work as expected when it's being used in the RpcExceptionFilter
Input Code
// Works correctly - client is receiving error with status 5 (NOT_FOUND)
@Controller()
class HeroController {
@GrpcMethod('HeroService', 'FindHero')
public async refreshToken(data: FindHeroRequest): Promise<FindHeroResponse> {
throw new RpcException({ code: 5, message: 'test'});
}
}
// Does not work as expected - Client is receiving error with code 2 (UNKNOWN)
@UseFilters(HeroExceptionFilter)
@Controller()
class HeroController {
@GrpcMethod('HeroService', 'FindHero')
public async refreshToken(data: FindHeroRequest): Promise<FindHeroResponse> {
throw new HeroException();
}
}
@Catch(HeroException)
export class HeroExceptionFilter implements RpcExceptionFilter {
public catch(exception: HeroException | Error, host: ArgumentsHost): Observable<unknown> {
return throwError(new RpcException({
code: 5,
message: "test",
}));
}
}
Expected behavior
RpcException thrown in exception filter should behave the same as being thrown in controller
From what I can see message property is passed correctly while code is not
Possible Solution
Environment
Nest version: 7.4.4
For Tooling issues:
- Node version: 14.13.1
- Platform: Linux
Others:
Bug Report
Current behavior
RpcException does not work as expected when it's being used in the
RpcExceptionFilter
Input Code
Expected behavior
RpcException thrown in exception filter should behave the same as being thrown in controller
From what I can see
message
property is passed correctly while code is notPossible Solution
Environment