Skip to content
This repository has been archived by the owner on Nov 11, 2023. It is now read-only.

Commit

Permalink
Do not report user aborted requests as errors
Browse files Browse the repository at this point in the history
  • Loading branch information
stereobooster authored and fabien0102 committed Dec 11, 2019
1 parent e1e9dae commit 9b75814
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/useGet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ async function _fetchData<TData, TError, TQueryParams>(

setState({ ...state, error: null, loading: false, data: resolve(data) });
} catch (e) {
// avoid state updates when component has been unmounted
// and when fetch/processResponse threw an error
if (signal.aborted) {
return;
}
setState({
...state,
loading: false,
Expand Down
6 changes: 6 additions & 0 deletions src/useMutate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ export function useMutate<
try {
data = resolve ? resolve(rawData) : rawData;
} catch (e) {
// avoid state updates when component has been unmounted
// and when fetch/processResponse threw an error
if (signal.aborted) {
return;
}

const error = {
data: e.message,
message: `Failed to resolve: ${e.message}`,
Expand Down

0 comments on commit 9b75814

Please sign in to comment.