You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When doing a client-side __data.json request, errors thrown with the error helper function inside hooks.server.ts , will not return the correct error object.
It works as expected when error gets thrown inside a +server.* file.
related: #7609
The issue was already described as a sidenote there.
Describe the proposed solution
SvelteKit should support throwing error objects also for __data.json requests inside hooks.server.ts.
This makes the usage of the error helper function more consistent.
Alternatives considered
Leave it as it is
Importance
would make my life easier
Additional Information
No response
The text was updated successfully, but these errors were encountered:
Thanks, but this looks really hacky and error-prone. Then I would prefer to return a regular Response object
// thisthrowerror(401,{message: 'Unauthhorized'})// would becomereturnResponse(JSON.stringify({message: 'Unauthorized'}),{status: 401,headers: {'content-type': 'application/json'}))
As you can see using the raw Response object makes you write additional boilerplate code. That's the reason why the error helper function was introduced by the SvelteKit team.
Adding support for throwing error inside handle makes it just more consistent with the rest of SvelteKit.
Describe the problem
When doing a client-side
__data.json
request, errors thrown with theerror
helper function insidehooks.server.ts
, will not return the correct error object.It works as expected when
error
gets thrown inside a+server.*
file.Here is a demonstration of the issue; https://stackblitz.com/edit/sveltejs-kit-template-default-djcepj?file=src/hooks.server.ts
hooks.servert.ts
related: #7609
The issue was already described as a sidenote there.
Describe the proposed solution
SvelteKit
should support throwingerror
objects also for__data.json
requests insidehooks.server.ts
.This makes the usage of the
error
helper function more consistent.Alternatives considered
Leave it as it is
Importance
would make my life easier
Additional Information
No response
The text was updated successfully, but these errors were encountered: