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

Make request headers available on the error page #15133

Closed
2 of 4 tasks
thijsw opened this issue Oct 10, 2022 · 3 comments
Closed
2 of 4 tasks

Make request headers available on the error page #15133

thijsw opened this issue Oct 10, 2022 · 3 comments

Comments

@thijsw
Copy link

thijsw commented Oct 10, 2022

Describe the feature

As described in this discussion thread, the request headers are not available on an error page. Therefore, cookies are not available either. So this code on a ~/error.vue page yield both null values. I am using server-side rendering.

const host = useCookie('name')
const headers = useRequestHeaders(['user-agent', 'host'])

I can imagine that it would be really useful to have this information available on an error page.

A potential "fix" could be easily implemented by passing the request headers to the $fetch function on this line:

let html = !isErrorPage
  ? await $fetch(withQuery('/__nuxt_error', errorObject), {
      headers: event.req.headers,
    }).catch(() => null)
  : null

Additional information

  • Would you be willing to help implement this feature?
  • Could this feature be implemented as a module?

Final checks

Copy link
Member

I completely understand the use case. The only question here is about caching, as if we pass headers, then we can't cache the error page result. (@pi0 - what do you think?)

@Luffyyy
Copy link

Luffyyy commented Oct 11, 2022

While I understand the less dependencies for error page does make sense especially if the error is a more "deep/core error", there are situations we just wanna do a 404 error and have everything under control. In my site at least, I do want to still show the user on the header and the headers being missing messes it up. Why not add an option for soft non-cachable errors?

@thijsw
Copy link
Author

thijsw commented Nov 4, 2022

Fixed by nuxt/framework#7340

@thijsw thijsw closed this as completed Nov 4, 2022
@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

No branches or pull requests

3 participants