question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Best practice way to handle and redirect 50X and 404 errors when querying sanity fetch

See original GitHub issue

Hey Nuxt Sanity team! I am looking for advice on error handling: When I query a page entry using the slug, I will need a way to do the following:

  • Redirect to the nuxt 404 error page if the query returns empty
  • Redirect and render the appropriate error when the query returns a 50X error

I am new to this module and I am not sure how best to do this. Can anyone share their method for doing so?

I am using Nuxt 3.0.0-rc.11 and Nuxt/sanity ^1.3.0

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
danielroecommented, Oct 27, 2022

You can follow https://github.com/nuxt/framework/pull/8521 - when this is merged, you can…

0reactions
toddpadwickcommented, Oct 27, 2022

That worked @danielroe thank you. One last question though – the error doesn’t provide an error status code – it’s just a boolean. How do determine the status code? It would be good to display a different error message based on whether it’s a network error as opposed to a server error?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Best practice way to handle and redirect 50X and 404 errors when ...
Hey Nuxt Sanity team! I am looking for advice on error handling: When I query a page entry using the slug, I will...
Read more >
Best Practices for Managing 404 Error Pages - Todhost Blog
If you have valuable links pointing to 404 pages, use a 301 redirect to correct and possibly contact the website owner for proper...
Read more >
fix(nuxt): pass async-data errors through to client by ... - GitHub
There will still be some differences between client + server errors because ... Best practice way to handle and redirect 50X and 404...
Read more >
404 When Hosting Sanity on Netlify
This might be a noob question, but we are struggling with 404 when hosting Sanity on Netlify. When visiting the site it will...
Read more >
Best Practices for Handling 404 Errors in Respect to SEO
Don't panic when your site has 404 errors · Review all the 404 links on Google and Bing Webmaster Tools · Add 301...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found