Category: Next.js, React and TypeScript

React Error Boundary does not catch rejected Promise in click

Read this guide in Polish

After an error while saving the Error Boundary form, it does not display a fallback, and the console shows an unhandled booking. React error limit refers to rendering and selected phases of components, not all of the errors in the dealers or async tasks.

How to identify the source of the problem

Check where the error occurs: render, event carrier, useEffect or Promise in API. Compare the behavior after the deliberate throw in the render to the error of the rejected fetch inside the onClick.

Compare the message from the console with the result of the production compilation and the condition after the page has been refreshed.

Repair steps

Use tri/catch, controlled error status and readable user message in the event handling. Use the Error Boundary for rendering failures, and transport and validation errors support in the form layer.

How to Test Solution

The API error shows the message in the form, and the rendering error separate fallback, without a white screen.

Security and restrictions

Do not assume that one Error Boundary replaces all asynchronous exceptions.