Skip to content

Commit

Permalink
ULMS-3243 Fixed unhandled error from http-client
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkonst committed Aug 8, 2024
1 parent dc89e2f commit 66b72da
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
20 changes: 11 additions & 9 deletions src/http-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) {
Expand Down

0 comments on commit 66b72da

Please sign in to comment.