Uh oh!
There was an error while loading. Please reload this page.
fix(nuxt): allow responding with custom headers from error.vue - #8469
Conversation
|
✅ Deploy Preview for nuxt3-docs canceled.
|
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| } | ||
| 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.
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.
yes. though note I just moved this up - this wasn't a change in this pr
There was a problem hiding this comment.
just tried - are you sure an error handler supports returning value directly? it seems to hang.
There was a problem hiding this comment.
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.
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...
thijsw
commented
Nov 9, 2022
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? |
danielroe
commented
Nov 9, 2022
@thijsw Would you create a discussion rather than commenting on a merged PR? |
🔗 Linked issue
follow-up to #7340, resolvesnuxt/nuxt#14895
❓ Type of change
📚 Description
This allows responding to an error within
error.vuewith more than just HTML and the original error code, such as modifying the code or redirecting to a different page.📝 Checklist