ap0nia / eden-query

🙏 type-safe Elysia.js client with powerful asynchronous state management.
https://ap0nia.github.io/eden-query/
MIT License
34 stars 3 forks source link

invalid error guard #46

Closed ap0nia closed 1 month ago

ap0nia commented 1 month ago

Issue

The ELYSIA_RESPONSE symbol was removed in elysia@1.1.18, and a new strategy has to be used for detecting whether or not an error was returned by a handler.

Solution

Check if the response is an instance of the ElysiaCustomStatusResponse or has the same constructor name.

Reasoning

When the handler returns an error, mapResponse should not be called because there isn't a valid response to map. If an "error-like" object is encountered, the transform plugin will not transform it. This allows the thrown error to be visible as an HTTP error on the client. This is important for tanstack-query to know when deciding whether or not to retry.

If tanstack-query receives a 200 OK response with no data, then it will print a warning and not retry since the request was supposedly successful.