NextJS best practice for handling "Server Error" and "Client side error"
22:47 28 Oct 2020

Using NextJS, I see 2 kinds of errors:

Server Error

  • generated it using throw new Error(...) inside getInitialProps...
  • it can occur due to some business logic or unexpected API response;
  • screenshot:

Server error

Unhandled Runtime Error

  • generated it using throw new Error(...) inside a component
  • it can occur due to some business logic;
  • the error here is captured by the ErrorBoundary (which is set inside _app.js)
  • screenshot:

Unhandled Runtime Error

Question: unhandled run time errors are captured inside Error Boundary (as they do in ReactJS)... how to best handle the 'server errors'... what is the best practice?

reactjs error-handling next.js server-error