Replies: 1 comment 2 replies
-
I think this might be a good idea, but note that we still can’t guarantee anything on type level because a runtime error can occur at any time in javascript, so even with the code above, we could still get errors from So, with that said, why is the shown code so much better than creating your own sub-class of error and doing:
then, you can check if |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently, the only way to "return an error" within a handler is by throwing it. Which does a pretty good job at catering for most use-cases. However, often it is useful to treat the error as a value and have its type inferred in the
error
prop of the query/mutation. This is especially useful if multiple errors can be "returned" and the UI needs to respond to each of them.If it helps, Elysia uses an
error()
helper to return errors from its handlers that tanstack/query may get inspiration from?Ideally, we'd have an API the looks something like,
Beta Was this translation helpful? Give feedback.
All reactions