diff --git a/package-lock.json b/package-lock.json index 188364c..d8802a1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@ulms/api-clients", - "version": "7.12.0", + "version": "7.12.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@ulms/api-clients", - "version": "7.12.0", + "version": "7.12.1", "license": "MIT", "dependencies": { "axios": "1.6.2", diff --git a/package.json b/package.json index 781a607..4c99b90 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ulms/api-clients", - "version": "7.12.0", + "version": "7.12.1", "description": "JavaScript API clients for ULMS platform", "keywords": [], "homepage": "https://github.com/foxford/ulms-api-clients-js#readme", diff --git a/src/http-client.js b/src/http-client.js index 4612c41..b05c25a 100644 --- a/src/http-client.js +++ b/src/http-client.js @@ -11,12 +11,13 @@ function createTimeoutSignal(timeout) { } class FetchHttpClient { - request(url, config) { + async request(url, config) { const { timeout, ...requestConfig } = config const requestOptions = { ...requestConfig, } let onFinally + let response if (timeout !== undefined) { const { cleanup, signal } = createTimeoutSignal(timeout) @@ -25,16 +26,17 @@ class FetchHttpClient { onFinally = cleanup } - const fetchPromise = fetch(url, requestOptions).catch((error) => { - throw new NetworkError('', { cause: error }) - }) - - if (onFinally) { - // eslint-disable-next-line promise/catch-or-return - fetchPromise.finally(() => onFinally()) + try { + response = fetch(url, requestOptions) + } catch (error) { + throw new NetworkError('network_error', { cause: error }) + } finally { + if (onFinally) { + onFinally() + } } - return fetchPromise + return response } get(url, config) {