jaridmargolin
Need more control over error handling
This is coming up as a result of some security testing against our API where we discovered that malformed URIs result in 500 errors (which in turn hit our error reporter).
We believe that these errors should be 400x errors, but it isn't entirely clear how to accomplish this.
In this particular case, the URIError is generated by tRPC itself, not our procedures, which means it's not as easy as wrapping the procedure and throwing the appropriate tRPC error instance.
Instead, the error bubbles up from tRPC internals and then gets handled by
getTRPCErrorFromUnknown
, where I have no control over using a BAD_REQUEST
error.
Ideally, we would be able to define the behavior of getTrpcErrorFromUnknown
and implement logic that checks instanceof URIError
and creates a BAD_REQUEST
error rather than an INTERNAL_SERVER_ERROR
.7 replies