A custom class for errors at `createStatusError`
- Dominant language
- TypeScript
- Stars
- 4.8k
- Forks
- 716
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 10
Description
### Is your feature request related to a problem? Please describe.
I want to catch errors thrown by gRPC, but I can't properly determine if one if from gRPC.
### Describe the solution you'd like
From the code, it looks like all errors I want to catch are thrown from here: https://github.com/grpc/grpc-node/blob/5e8e08e09582a8a17664dd6dff60290f13140304/packages/grpc-native-core/src/common.js#L79-L92
I'd like that `let error = new Error(message);` to be `let error = new GrpcError(message);` and for it to be a subclass of a regular `Error`, so that I can do `if(e instanceof GrpcError) {...}`.
### Describe alternatives you've considered
Alternatively I can use heuristics to determine whether the error is from gRPC or not, but it's not really correct. I'll take that approach in my implementation for now, because it available already, but I don't like it.
In terms of solutions, alternative is for gRPC to explicitly provide the function to determine if passed object is an error thrown by grpc-node, with a signature like `isGrpcError(e: any): e is GrpcError` in TypeScript syntax.
### Additional context
I'm adding a custom login in the central location to just decorate how gRPC errors look in the responses (in a GraphQL server).
Contributor guide
Assessment
This issue has not been assessed yet.