-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix(nuxt): allow responding with custom headers from error.vue
#8469
Conversation
|
β Deploy Preview for nuxt3-docs canceled.
|
@@ -63,9 +65,13 @@ export default <NitroErrorHandler> async function errorhandler (error: H3Error, | |||
// TODO: Support `message` in template | |||
(errorObject as any).description = errorObject.message | |||
} | |||
html = template(errorObject) | |||
event.res.setHeader('Content-Type', 'text/html;charset=UTF-8') | |||
return event.res.end(template(errorObject)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we please return string? H3 will add content-type too and also handles sending response string. Reducing req/res dependency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes. though note I just moved this up - this wasn't a change in this pr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just tried - are you sure an error handler supports returning value directly? it seems to hang.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can check. But seems strange because it is a nitro API route right?
} | ||
|
||
event.res.setHeader('Content-Type', 'text/html;charset=UTF-8') | ||
event.res.end(html) | ||
event.respondWith(new H3Response(await res.text(), { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
respond with API is not stable yet and might change. Let's use raw methods for now. I will have an idea for a way to simplify and standardized response format for nitro...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good!
I'd like to use this feature but I'm not sure how to use it? Does anybody might want to share an example of how I can redirect a user on the error page? |
@thijsw Would you create a discussion rather than commenting on a merged PR? |
π Linked issue
follow-up to #7340, resolves nuxt/nuxt#14895
β Type of change
π Description
This allows responding to an error within
error.vue
with more than just HTML and the original error code, such as modifying the code or redirecting to a different page.π Checklist