swr icon indicating copy to clipboard operation
swr copied to clipboard

Filter out browser cancellation errors automatically

Open shuding opened this issue 2 years ago • 0 comments

More information about this can be found in https://request-cancellation-test.vercel.app. What SWR can help here is to provide an ignoreCancellationErrors option which skips onError and onErrorRetry callbacks when an error matches that pattern occurred.

This is helpful for cases like using Sentry to report client errors, or showing a “failed to fetch” hint in the UI. It's very tricky to filter these errors out manually due to the ununified behaviors.

However, there are many concerns about this change. Since we can't avoid the error state being updated, it will mostly be a consistency issue (error is set but onError isn't fired). So should we name it as ignoreCancellationErrorReports or skipCancellationErrorEvents? Or we should provide a shouldIgnoreError: error => boolean option (a filter), and give it a default value?

shuding avatar Dec 22 '21 17:12 shuding