From 1abf095bbde6ed4b3f47aa637219a41623475dde Mon Sep 17 00:00:00 2001 From: Fabien BERNARD Date: Fri, 27 Mar 2020 13:19:26 +0100 Subject: [PATCH] Trigger `onError` on useGet catch case --- src/useGet.tsx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/useGet.tsx b/src/useGet.tsx index 0fac797e..2044b464 100644 --- a/src/useGet.tsx +++ b/src/useGet.tsx @@ -138,14 +138,21 @@ async function _fetchData( 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)); + } } }