Skip to content

Commit

Permalink
fix: error handling delete empty response
Browse files Browse the repository at this point in the history
  • Loading branch information
pviti committed Jun 11, 2024
1 parent f880988 commit 21730ce
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@ export const fetchURL = async (url: URL, requestOptions: FetchRequestOptions, cl
if (interceptors?.rawReader?.onFailure) await interceptors.rawReader.onFailure(response)
}

const responseBody = await response.json()
const responseBody = response.body ? await response.json()
.then(json => { debug('response: %O', json); return json })
.catch((err: Error) => { debug('error: %s', err.message); throw new SdkError({ message: 'Error parsing API response body', type: ErrorType.PARSE }) })

: undefined

if (!response.ok) {
let error = new FetchError(response.status, response.statusText, responseBody)
if (interceptors?.response?.onFailure) error = await interceptors.response.onFailure(error)
Expand Down

0 comments on commit 21730ce

Please sign in to comment.