You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I throw an error inside an interceptor, I expect to receive that error when I wrap my RPC method in a try/catch. Instead, I receive an [unknown] type. If I wrap my error in a ConnectError.from, I receive an ConnectError: [unknown].
My usecase:
The framework I'm using is waiting for a specific error instance, a ServerError, to correctly set the HTTP status code. It would be simple to have an interceptor catch ConnectErrors and throw ServerErrors. But since the ServerError is not surfaced on the other side, it requires every calling function to be wrapped in a try/catch and converted to the new error type.
This is my interceptor code:
// Simply used to map error codesconstERRORS={[Code.Canceled]: 499,// ...}// This would be inside the createConnectTransport interceptors list(next)=>async(req)=>{try{returnawaitnext(req)}catch(err){if(errinstanceofConnectError){consthttpStatus=ERRORS[err.code]if(httpStatus){thrownewServerError(httpStatus,err)}}thrownewServerError(500,err)}}
To Reproduce
If you encountered an error message, please copy and paste it verbatim.
If the bug is specific to an RPC or payload, please provide a reduced
example.
Environment (please complete the following information):
Hey Dustin. The API was designed to support clients with strong error types, and errors are wrapped to ConnectErrors eagerly.
Maybe it makes sense to revise this design. It looks like the change is simple (reject promise with reason instead of e in run-call.ts). But there may be side effects, and it's technically a breaking change. So this needs to be considered carefully, and it's not something we can change quickly.
There's a simple alternative though - instead of adding and interceptor, you can wrap the client:
Describe the bug
When I throw an error inside an interceptor, I expect to receive that error when I wrap my RPC method in a try/catch. Instead, I receive an [unknown] type. If I wrap my error in a
ConnectError.from
, I receive anConnectError: [unknown]
.My usecase:
The framework I'm using is waiting for a specific error instance, a
ServerError
, to correctly set the HTTP status code. It would be simple to have an interceptor catch ConnectErrors and throw ServerErrors. But since the ServerError is not surfaced on the other side, it requires every calling function to be wrapped in a try/catch and converted to the new error type.This is my interceptor code:
To Reproduce
If you encountered an error message, please copy and paste it verbatim.
If the bug is specific to an RPC or payload, please provide a reduced
example.
Environment (please complete the following information):
If your problem is specific to bundling, please also provide the following information:
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: