Does the RequestHandler modify thrown errors? How to consistently handle with internal and external API errors? #6603
Unanswered
kevinrenskers
asked this question in
Q&A
Replies: 2 comments 3 replies
-
|
So the end result is that errors now look like this 🙈 |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
This will be aligned with #6586 . |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Uh oh!
There was an error while loading. Please reload this page.
-
I'm not sure how to write my API layer so that errors from internal and external endpoints are consistently handled by the app's pages.
For example, my API layer looks like this:
So anywhere in my app I can for example call
postApiin atry/catchblock, and the error is an object with status, message anderrors, which is the raw dictionary of field errors from the server (form validation errors, stuff like that). This all works fine.I also have an external API endpoint that I call via my own internal SvelteKit endpoint, because the endpoint returns a token on successful login, in which case I store it in a cookie. The internal endpoint looks like this:
it just uses the same
postApimethod from above. To call this internal endpoint, I do it like this in a route page:So it calls the internal endpoint
${websiteUrl}/auth/exchange-magic-token, which calls the external endpoint. The problem is the error handling: when the server returns an error, I don't get the usual error object that I would expect, instead it's wrapped in something else.For example calling
await postApi<{ token: string }>(fetch, "/auth/exchange-magic-token", payload)(which calls the external endpoint) with a wrong payload can result in an error like this:But calling
await postApi<{ token: string }>(fetch, "${websiteUrl}/auth/exchange-magic-token", payload)(so, via the internal SvelteKit endpoint) results in an error like this:Why is my error object wrapped inside something else all of a sudden, stringified and all? How do I stop this from happening? Or how do I make sure that errors are consistent and can be handled in a consistent way?
Beta Was this translation helpful? Give feedback.
All reactions