Skip to content

Commit

Permalink
Trigger onError on useGet catch case
Browse files Browse the repository at this point in the history
  • Loading branch information
fabien0102 committed Mar 27, 2020
1 parent 88db463 commit 3e4b4e0
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/useGet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,21 @@ async function _fetchData<TData, TError, TQueryParams>(
if (signal && signal.aborted) {
return;
}

const error = {
message: `Failed to fetch: ${e.message}`,
data: e.message,
};

setState({
...state,
loading: false,
error: {
message: `Failed to fetch: ${e.message}`,
data: e.message,
},
error,
});

if (!props.localErrorOnly && context.onError) {
context.onError(error, () => _fetchData(props, state, setState, context, abort, getAbortSignal));
}
}
}

Expand Down

0 comments on commit 3e4b4e0

Please sign in to comment.