NCIOCPL / clinical-trials-search-app

Clinical Trial Search Front-end
1 stars 6 forks source link

(#625) Incorrect prerender-status-code on API error #632

Closed adriancofie closed 1 week ago

adriancofie commented 1 week ago

(#625) Add pre-render metatag, error handling

Notes:

Why react-error-boundary?

An error-boundary follows best practices however the default react ErrorBoundary is lacking in several annoying ways.

The React documentation mentions it as an alternative (https://react.dev/reference/react/Component#componentdidcatch) and it is vetted by the community with over 4million weekly downloads (https://www.npmjs.com/package/react-error-boundary) and key endorsements (https://kentcdodds.com/blog/use-react-error-boundary-to-handle-errors-in-react).


More error handling please.

This ticket adds some basic error handling and the ErrorBoundary wrapper however there are more areas where error handling can be made robust and detailed, particularly for the bulk of the fetchers. As they are not the priority for this ticket that is left for a rainy day.

The idea is to incrementally transition to the more detailed centralized error handling in this ticket as the opportunities arise. IE. Not one large refactor ticket but code quality improvements being baked into existing tickets.


Cypress is suppressing exceptions by default

We're currently (on the dev/main branches) globally suppressing uncaught exceptions during the cypress runtime. Or at least intending to.

// https://docs.cypress.io/guides/guides/error-handling#Handling-uncaught-exceptions // May have issues with async code. Explicitly handle as needed. Also, this hides errors. cy.on('uncaught:exception', () => { // returning false here prevents Cypress from // failing the test return false; });

As I noted 1. this seems very heavy handed and defeats part of the purpose of having automated tests. 2. Globally suppressing the exceptions doesn't seem to work under all circumstances. A better approach would be to only suppress uncaught exceptions under precise and accounted for circumstances (For example...when exceptions caught by the ErrorBoundary are displayed in the console as "uncaught" in version of React < 19 https://react.dev/blog/2024/04/25/react-19#error-handling. )

Potentially related: https://github.com/cypress-io/cypress/issues/22129

github-actions[bot] commented 1 week ago

Viewing Information