#SSR error results in last non-error response to be rendered

6 messages · Page 1 of 1 (latest)

dry blade
#

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:

  1. Load the application
  2. change the url of asyncdata to https://httpbin.org/status/500
  3. See that the error state is shown and an error is logged
  4. Refresh the stackblitz browser frame using the refresh button in the UI
  5. See that the last successful render is being rendered (text "hello"), while the error is still logged
StackBlitz

Create a new Nuxt project, module, layer or start from a theme with our collection of starters.

dry blade
#

@devout meteor do you perhaps know if this is a bug, feature or missing configuration?

devout meteor
#

I think it's designed to avoid capturing/caching an error page

dry blade
#

But this does mean that if a user requests a page that is having issues, the user will get outdated data. Potentially resulting in further issues that will be hard to reproduce.

Shouldn't this behavior be optional?

devout meteor
dry blade
#

Awesome, i will.