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

Question: How to handle Errors #188

Open
lautiamkok opened this issue Jan 20, 2023 · 0 comments
Open

Question: How to handle Errors #188

lautiamkok opened this issue Jan 20, 2023 · 0 comments

Comments

@lautiamkok
Copy link

lautiamkok commented Jan 20, 2023

Is there any guide on how to handle errors, e.g. 500, on the server side? I still can't figure out how to do it with this plugin:

export default viteSSR(App, 
  { 
    routes 
  }, 
  ({ url, app, router, initialState, request, isClient, writeResponse, redirect }) => {
    const head = createHead()
    app.use(head)

    app.config.errorHandler = (err, vm, info) => {
      const statusCode = err.statusCode ? err.statusCode : 500

      // Reload browser so that the error is handled on SSR instead.
      if (isClient) {
         location.reload()
       }

       if (import.meta.env.SSR) {
         writeResponse({
           status: statusCode,
           html: err.message // how can we pass the app html here?
        })
       }
    }
    return { head }
  }
)

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant