Skip to content

Commit

Permalink
fix: allow retry: false
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Nov 4, 2021
1 parent 8b89c9c commit ce8e4d3
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface FetchOptions extends Omit<RequestInit, 'body'> {
params?: SearchParams
parseResponse?: (responseText: string) => any
response?: boolean
retry?: number
retry?: number | false
}

export interface FetchResponse<T> extends Response { data?: T }
Expand Down Expand Up @@ -65,12 +65,14 @@ export function createFetch ({ fetch }: CreateFetchOptions): $Fetch {
const parseFn = opts.parseResponse || destr
response.data = parseFn(text)
if (!response.ok) {
const retries = opts.retry ?? (hasPayload ? 0 : 1)
if (retries > 0) {
return $fetchRaw(request, {
...opts,
retry: retries - 1
})
if (opts.retry !== false) {
const retries = typeof opts.retry === 'number' ? opts.retry : (hasPayload ? 0 : 1)
if (retries > 0) {
return $fetchRaw(request, {
...opts,
retry: retries - 1
})
}
}
throw createFetchError(request, response)
}
Expand Down

0 comments on commit ce8e4d3

Please sign in to comment.