Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpError and Redirect import errors #6009

Closed
denovodavid opened this issue Aug 18, 2022 · 3 comments · Fixed by #11165
Closed

HttpError and Redirect import errors #6009

denovodavid opened this issue Aug 18, 2022 · 3 comments · Fixed by #11165
Labels
feature request New feature or request
Milestone

Comments

@denovodavid
Copy link

Describe the bug

I'm building my own adapter with typescript, and I use tsc -b to build it.
Since the new routing change, I get a type error when building (see reproduction).

Also: HttpError and Redirect classes are not available to import, which they probably should be since we indirectly throw them and might want to handle them differently if thrown around with other errors.

See also Rich's comment here: #5952 (comment)

Also also, not directly related but still weird typing issue: I had to add @types/estree to dependencies to appease svelte, seems related to: sveltejs/svelte#3397

Reproduction

https://stackblitz.com/edit/node-sfis81?file=index.ts

Logs

No response

System Info

System:
    OS: Windows 10 10.0.19044
    CPU: (8) x64 Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz    
    Memory: 1.41 GB / 15.75 GB
  Binaries:
    Node: 16.16.0 - ~\AppData\Local\nvs\default\node.EXE     
    npm: 8.11.0 - ~\AppData\Local\nvs\default\npm.CMD        
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (104.0.1293.54)
    Internet Explorer: 11.0.19041.1566
  npmPackages:
    @sveltejs/kit: 1.0.0-next.420 => 1.0.0-next.420 
    svelte: ^3.49.0 => 3.49.0 
    vite: ^3.0.8 => 3.0.8

Severity

serious, but I can work around it

Additional Information

No response

@tcc-sejohnson
Copy link
Contributor

tcc-sejohnson commented Aug 18, 2022

For what it's worth, I support exposing these. "You can throw it but you can't catch it" seems kind of like an antipattern. Even better, an export like isRedirect/isHttpError so that we can maintain encapsulation of those classes:

export const isRedirect = (err: unknown): err is Redirect => { /* implementation */ }

@Rich-Harris Rich-Harris added this to the post-1.0 milestone Sep 6, 2022
@Rich-Harris Rich-Harris added the feature request New feature or request label Sep 6, 2022
@pjebs
Copy link

pjebs commented Dec 9, 2022

My workaround for now (for my purposes):

class Wrap {
	public obj;
	constructor(x) {
		this.obj = x;
	}
}

throw new Wrap(redirect(status, data));
// or 
throw new Wrap(error(500, ""));


...


} catch (e) {
	if (e instanceof Wrap) {
		throw e.obj;
	}
...
}

@mike-lloyd03
Copy link

Is there any other recommended way to catch an HttpError? A fetch request to my backend API can throw HttpErrors and Redirects. I'd like to handle errors and throw Redirects but I don't see a way to do this as of now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
6 participants