Skip to content

Commit c3785fb

Browse files
committed
fix: handle abort errors in API calls and improve error handling in callApi function
1 parent a94ebf8 commit c3785fb

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

adminforth/spa/src/utils/listUtils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ export async function getList(resource: AdminForthResourceFrontend, isPageLoaded
2929
},
3030
abortSignal: abortController.signal
3131
});
32+
if (abortController.signal.aborted) {
33+
return;
34+
}
3235
if (data.error) {
3336
showErrorTost(data.error);
3437
rows = [];

adminforth/spa/src/utils/utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ export async function callApi({path, method, body, headers, silentError = false,
149149
}
150150
return await r.json();
151151
} catch(e) {
152+
if (e instanceof DOMException && e.name === 'AbortError') {
153+
return null;
154+
}
155+
152156
// if it is internal error, say to user
153157
if (e instanceof TypeError && e.message === 'Failed to fetch') {
154158
// this is a network error
@@ -158,7 +162,7 @@ export async function callApi({path, method, body, headers, silentError = false,
158162
return null;
159163
}
160164

161-
if (!silentError && !(e instanceof DOMException && e.name === 'AbortError')) {
165+
if (!silentError) {
162166
adminforth.alert({variant:'danger', message: t('Something went wrong, please try again later'),})
163167
}
164168
console.error(`error in callApi ${path}`, e);

0 commit comments

Comments
 (0)