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
Not sure if this is a bug - or I missed something in the documentation - but I have the following problem.
I want to fetch some things from an external API in my +page.server.ts. I have some helper functions in $lib/server/ that help me to do that.
In these, if I encounter error in the external API, I throw errors with something along the lines of:
exportasyncfunctionfetch_thing(parameter: string){constresponse=awaitfetch(`${base_url}/api/thing/${parameter}`);if(!response.ok){constexternal_error_message=JSON.stringify((awaitresponse.json()).detail);throwerror(response.status,`could not fetch from external API: ${external_error_message}`);}returnthing_schema.parse(awaitresponse.json());}
In my +page.server.ts I then catch these with something along the lines of:
import{HttpError}from'@sveltejs/kit';
...
try{awaitfetch_thing(parameter);}catch(e){if(einstanceofHttpError&&e.status===422){// do something}}
but that results in:
TypeError: Right-hand side of 'instanceof' is not an object
It turns out that HttpError is undefined!
This is surprising to me:
Is HttpError not meant for consumption so to speak? Am I doing something weird here?
If I'm not supposed to use HttpError then maybe that should be documented somewhere?
Describe the bug
Hi!
Not sure if this is a bug - or I missed something in the documentation - but I have the following problem.
I want to fetch some things from an external API in my
+page.server.ts
. I have some helper functions in$lib/server/
that help me to do that.In these, if I encounter error in the external API, I throw errors with something along the lines of:
In my
+page.server.ts
I then catch these with something along the lines of:but that results in:
It turns out that
HttpError
is undefined!This is surprising to me:
![Screenshot 2023-06-27 at 21 39 42](https://private-user-images.githubusercontent.com/31876997/249268784-dd88d968-7696-4cc6-af67-81d751e2eebb.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg4NjY4MDQsIm5iZiI6MTczODg2NjUwNCwicGF0aCI6Ii8zMTg3Njk5Ny8yNDkyNjg3ODQtZGQ4OGQ5NjgtNzY5Ni00Y2M2LWFmNjctODFkNzUxZTJlZWJiLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA2VDE4MjgyNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQzMGVjNWQ1MmMwNmEyODhmODYyNjllNDFmNmEwNzY1MDBmZDUyOWYyYzk2MDE1M2Q3ZDJiNWQ2ZTM2MGYxZWUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.kn6yllTgBuZjg-KSKcxZfdUoCIgnx0Bgr6ltMZmEKOw)
Is
HttpError
not meant for consumption so to speak? Am I doing something weird here?If I'm not supposed to use
HttpError
then maybe that should be documented somewhere?Reproduction
https://stackblitz.com/edit/sveltejs-kit-template-default-bmtmun?file=src%2Froutes%2F%2Bpage.server.ts
press Demo
Logs
TypeError: Right-hand side of 'instanceof' is not an object
System Info
Severity
annoyance
Additional Information
No response
The text was updated successfully, but these errors were encountered: