Cybermuse.io
Error handling abort on unstable_httpBatchStreamLink
Handling the error by message seems to be workable. The generateMessage function works.
Just that handling by error message seems a bit fragile. The error name is just "error", and the message seems to imply that this error could likely be used for other types of errors that should be propogated.
11 replies
Error handling abort on unstable_httpBatchStreamLink
Its a very similar story with a plain browser fetch request. When you abort, it throws an error. In that case, the error will be an instanceof DOMException with a name of "AbortError".
11 replies
Error handling abort on unstable_httpBatchStreamLink
I have a call to get a streaming text response called generateMessage.
If the user wants to stop the response early, then calling abort seems like the correct way to do so. Calling abort causes the TRPC client to throw an error. That error should be swallowed, not propogated up or displayed. However any other errors, like a network failure or validation error should be propagated.
11 replies
Error handling abort on unstable_httpBatchStreamLink
I don't know that its necessarily a bug. The error in question is defined here.
https://github.com/trpc/trpc/blob/52a57eaa9c12394778abf5f0e6b52ec6f46288ed/packages/server/src/unstable-core-do-not-import/stream/jsonl.ts#L338
And you have a test for it.
https://github.com/trpc/trpc/blob/52a57eaa9c12394778abf5f0e6b52ec6f46288ed/packages/tests/server/streaming.test.ts#L325
I'm just not sure of how to correctly handle it.
Just doing a string comparison on the error message seems to do the trick. That feels a little fragile though.
11 replies