Skip to content
This repository has been archived by the owner on Mar 28, 2024. It is now read-only.

Commit

Permalink
style(fetch): code format
Browse files Browse the repository at this point in the history
  • Loading branch information
alimd committed Dec 19, 2023
1 parent 640ce6a commit 8a50074
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions packages/fetch/src/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export async function serviceRequest<T extends AlwatrServiceResponse = AlwatrSer
let response: Response;
try {
response = await fetch(options);
} catch (err) {
}
catch (err) {
const errMessage = (err as Error).message;
if (errMessage !== 'fetch_cache_not_found') {
logger.error('serviceRequest', (err as Error).message || 'fetch_failed', err, options);
Expand All @@ -44,7 +45,8 @@ export async function serviceRequest<T extends AlwatrServiceResponse = AlwatrSer
let responseText: string;
try {
responseText = await response.text();
} catch (err) {
}
catch (err) {
logger.error('serviceRequest', 'invalid_response', err, {
response,
});
Expand All @@ -54,7 +56,8 @@ export async function serviceRequest<T extends AlwatrServiceResponse = AlwatrSer
let responseJson: T;
try {
responseJson = JSON.parse(responseText);
} catch (err) {
}
catch (err) {
logger.error('serviceRequest', 'invalid_json', err, {responseText});
throw err;
}
Expand All @@ -63,7 +66,8 @@ export async function serviceRequest<T extends AlwatrServiceResponse = AlwatrSer
if (typeof responseJson.errorCode === 'string') {
logger.accident('serviceRequest', responseJson.errorCode, {responseJson});
throw new Error(responseJson.errorCode);
} else {
}
else {
logger.error('serviceRequest', 'fetch_nok', {responseJson});
throw new Error('fetch_nok');
}
Expand Down Expand Up @@ -200,7 +204,8 @@ async function _handleCacheStrategy(options: Required<FetchOptions>): Promise<Re
cacheStorage.put(request, networkResponse.clone());
}
return networkResponse;
} catch (err) {
}
catch (err) {
const cachedResponse = await cacheStorage.match(request);
if (cachedResponse != null) {
return cachedResponse;
Expand Down Expand Up @@ -263,7 +268,8 @@ async function _handleRemoveDuplicate(options: Required<FetchOptions>): Promise<
}

return response.clone();
} catch (err) {
}
catch (err) {
// clean cache on any error.
delete duplicateRequestStorage[cacheKey];
throw err;
Expand All @@ -289,7 +295,8 @@ async function _handleRetryPattern(options: Required<FetchOptions>): Promise<Res
}
// else
throw new Error('fetch_server_error');
} catch (err) {
}
catch (err) {
logger.accident('fetch', 'fetch_failed_retry', err);

if (globalScope.navigator?.onLine === false) {
Expand Down

0 comments on commit 8a50074

Please sign in to comment.