-
Notifications
You must be signed in to change notification settings - Fork 244
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
Failed requests break SSR even if they are handled #166
Comments
This issue as been imported as question since it does not respect axios-module issue template. Only bug reports and feature requests stays open to reduce maintainers workload. |
Hey @pi0 I think it's a bug and not a question |
Hey @megapctr. Actually, it is not a bug for this module and to be honest something expected with the current version of nuxt. Any thrown error in AsyncData/Fetch/Plugins/NuxtServerInit will cause SSR errors. We can improve it for sure. One possible application-wide solution would be returning a fallback value in onResponseError() {
// ...
return Promise.resolve({ error: true })
} The better idea would be to handle them inside async asyncData({ app }) {
const something = await app.$axios.$get('...')
.catch(() => Promise.resolve({ error: true }))
// something === { error: true } in case of any error |
Thanks! Turns out the fix is even simpler, at least in my case: export default function({ $axios, store }) {
- $axios.onResponseError(e => {
+ $axios.onResponseError(async e => {
const { status, data } = e.response 😁 |
@megacpr Your welcome and happy your problem is resolved. Please also note that in case of error, e.response is not always defined. |
I have a nuxt app with a
onResponseError
handler for handling exceptions.The handler works great in client mode:
But in server mode (SSR) the entire render breaks if a request fails:
...even though my handler is being called correctly in SSR:
I think that SSR should render a page with the alert, just like in the client mode. Am I doing something wrong?
The text was updated successfully, but these errors were encountered: