Skip to content

Commit

Permalink
fix: fix empty body response
Browse files Browse the repository at this point in the history
  • Loading branch information
pviti committed Jun 11, 2024
1 parent 2e46f33 commit f93ba83
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const fetchURL = async (url: URL, requestOptions: FetchRequestOptions, cl

if (interceptors?.request?.onSuccess) ( { url, options: requestOptions } = await interceptors.request.onSuccess({ url, options: requestOptions }) )

// const request: Request = new Request(url, requestOptions)
// const request: Request = new Request(url, requestOptions) // not supported by all fetch implementations

const fetchClient = clientOptions?.fetch || fetch

Expand All @@ -65,7 +65,9 @@ export const fetchURL = async (url: URL, requestOptions: FetchRequestOptions, cl
if (interceptors?.rawReader?.onFailure) await interceptors.rawReader.onFailure(response)
}

const responseBody = await response.json().catch(() => {})
const responseBody = await response.json()
.then(json => { debug('response: %O', json); return json })
.catch(err => { debug('error: %s', err.message) })

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

0 comments on commit f93ba83

Please sign in to comment.