Skip to content

Eden 1.4.6 introduced breaking behaviour change in error throwing semantics #246

@heiwen

Description

@heiwen

What steps can reproduce the bug?

The PR "Fix: Handle network errors in treaty and edenFetch" introduced a breaking behaviour change in how Eden treats errors.

Up to Eden 1.4.5, any error thrown by the fetch client bubbled through as an exception to the consumer. Since Eden 1.4.6, all errors are wrapped into the result.error object. While the stated intent of the PR was to captures NetworkErrors (like timeouts), it also captures any errors thrown by a custom fetcher client.

I use Eden with ky and set throwHttpErrors to throw on 500 and a few other errors (and to automatically handle retires / timeouts). Basically any error, that my application logic cannot handle. These errors automatically bubble up to my framework error boundary, which takes care of raising them to the user. This helps me to avoid writing boilerplate code with every Eden request.

Suggestion: I see how the newly implemented behaviour can be useful in some places of my code. It would be great if it is configurable though, via a generic throwHttpErrors parameter on Eden treaty, as well as an override on query level. If that parameter is set, any error from Eden (including HTTP Errors) are thrown. If it is not set, all errors are wrapped into the result.data object (like today). An advanced version would allow a function input, to configure which errors to throw / which ones to wrap (like the ky version allows to do).

This would be inline with the behaviour of other clients, like TanStack query: https://tkdodo.eu/blog/react-query-error-handling

CC @SaltyAom @truehazker

What version of Elysia is running?

Elysia 1.4.22 / Eden 1.4.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions