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

Handle errors during URL fetching #286

Merged
merged 3 commits into from
Mar 1, 2022
Merged

Conversation

kylelaker
Copy link
Contributor

@kylelaker kylelaker commented Mar 1, 2022

Because OSCALLoader itself is the top-level component that has an
<ErrorBoundary> as a child, we cannot rely on the <ErrorBoundary> to
catch errors further in the stack. Additionally, Error Boundaries do a
poor job of catching asynchronous errors. Instead, we track error state
(which we did prior to #267, though, this implementation is a little
cleaner as we don't try to pass the onError further down the call
stack since we can use the <ErrorBoundary> for that.

Since we've refactored the logic to handle the error into its own
(reused) function, it's now also trivial to set the loaded and
isResolutionComplete variables, which means we can also re-enable the
"Reload" button even after an error.

Resolves #283
Resolves #163

@kylelaker
Copy link
Contributor Author

An earlier version of this work did leverage e7c9642 but this current implementation doesn't. I am going to rebase this work to split that commit into its own PR and cleanup the history on this PR.

@kylelaker kylelaker force-pushed the feature/fix-unhandled-errors branch from ac8bfa7 to d19be32 Compare March 1, 2022 04:53
@kylelaker
Copy link
Contributor Author

kylelaker commented Mar 1, 2022

Samples of a few different error types; both ones fixed by #267 and ones that worked before (and some that worked after), some occur in the fetch, others in other places.

404 URL:
image

No CORS:
image

200 with a non-JSON response (fetch interprets all non-absolute URIs as relative):
image

SSP passed to the Catalog Viewer:
image

@kylelaker kylelaker force-pushed the feature/fix-unhandled-errors branch from d19be32 to 20dd12e Compare March 1, 2022 05:33
Because `OSCALLoader` itself is the top-level component that has an
`<ErrorBoundary>` as a child, we cannot rely on the `<ErrorBoundary>` to
catch errors further in the stack. Additionally, Error Boundaries do a
poor job of catching asynchronous errors. Instead, we track error state
(which we did prior to #267, though, this implementation is a little
cleaner as we don't try to pass the `onError` further down the call
stack since we _can_ use the `<ErrorBoundary>` for that.

Since we've refactored the logic to handle the error into its own
(reused) function, it's now also trivial to set the `loaded` and
`isResolutionComplete` variables, which means we can also re-enable the
"Reload" button even after an error.

Resolves #283
Resolves #163
@kylelaker kylelaker force-pushed the feature/fix-unhandled-errors branch from 20dd12e to e738eca Compare March 1, 2022 05:49
Copy link
Contributor

@hreineck hreineck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix!

Copy link
Contributor

@rgauss rgauss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor, unrelated suggestion.

src/components/ErrorBoundary.js Outdated Show resolved Hide resolved
We actually have no means to "look into it" (right now).
This allows displaying a more friendly error text but also expanding it
to view the specific details.
@kylelaker kylelaker merged commit 6838b39 into develop Mar 1, 2022
@kylelaker kylelaker mentioned this pull request Mar 1, 2022
4 tasks
@rgauss rgauss deleted the feature/fix-unhandled-errors branch March 2, 2022 18:24
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

Successfully merging this pull request may close these issues.

Loading of Non-Existent URL Doesn't Display Error Reload Button Stays Disabled on Failed URL Fetch
3 participants