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

[nitro] H3 error is not forwarded from an import #11769

Closed
atinux opened this issue Jul 26, 2021 — with Volta.net · 7 comments · Fixed by nuxt/framework#389
Closed

[nitro] H3 error is not forwarded from an import #11769

atinux opened this issue Jul 26, 2021 — with Volta.net · 7 comments · Fixed by nuxt/framework#389

Comments

Copy link
Member

atinux commented Jul 26, 2021

It seems the H3 error is not detected when used from another file.

Reproduction: https://codesandbox.io/s/shy-tdd-7oe13?file=/server/api/fails.ts

Works: https://7oe13.sse.codesandbox.io/api/works
Fails: https://7oe13.sse.codesandbox.io/api/fails

Screenshot 2021-07-26 at 18.13.55.png

@atinux atinux added the bug label Jul 26, 2021 — with Volta.net
Copy link
Member

danielroe commented Jul 26, 2021

The difference is just between return createError and throw createError. The first one returns the error object as JSON but no error is ever thrown.

@pi0
Copy link
Member

pi0 commented Jul 26, 2021

As a feature, we can support returning an error object for h3 but indeed it works as expected. (unjs/h3#28)

Copy link
Member Author

atinux commented Jul 26, 2021

I see, it would be nice to have a different error page for api (sending back json).

@pi0
Copy link
Member

pi0 commented Jul 26, 2021

@atinux It happens when using curl or JSON client (https://github.com/nuxt/framework/blob/0e93d752fd128dd93e1f59c35ac8d4a95ff0aebb/packages/nitro/src/runtime/server/error.ts#L11) same as nuxt2 but would be nice idea indeed passing formatted JSON object to error page :)

Copy link
Member Author

atinux commented Jul 26, 2021

That would be great indeed 😀

@pi0
Copy link
Member

pi0 commented Jul 26, 2021

Hmm looking again, we have statusCode as header, statusMessage as the first line of message and rest of stack. Errors seem okay and not missing anything from json version but Internal Server Error

image

image

@danielroe danielroe linked a pull request Jul 27, 2021 that will close this issue
1 task
@danielroe
Copy link
Member

Will be closed with linked renovate PR - see unjs/h3@991fcff.

@danielroe danielroe added the 3.x label Jan 19, 2023
@danielroe danielroe transferred this issue from nuxt/framework Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants