Hi,
I'm wondering if i'm missing some configuration option here or running into a bug in Nuxt/Nitro.
In my page, i perform an API request to an external server, and the results are rendered in a Vue component using the following route rules configuration:
routeRules: {
'**': {
ssr: true,
cache: {
maxAge: 60
},
},
},
This works fine, but when that api request fails (due to a 500 from the external server for instance), the route is still being served with a 200 response code and shows the last rendered data that was from the last succeeding api request.
In my page, i have an if-statement that checks if the response was faulty, and if so throw an error using throw createError({ statusCode: 500, statusMessage: 'Internal server error' });. This error is being logged to the console by Nuxt/Nitro.
Is there any way to make sure that if the api request fails, the Nuxt server returns a 500 with the error page?
Sample repo: https://stackblitz.com/edit/github-45sxb2-8etcop?file=app.vue,nuxt.config.ts
To reproduce, follow these steps:
- Load the application
- change the url of asyncdata to https://httpbin.org/status/500
- See that the error state is shown and an error is logged
- Refresh the stackblitz browser frame using the refresh button in the UI
- See that the last successful render is being rendered (text "hello"), while the error is still logged