diff --git a/src/fetch.ts b/src/fetch.ts index 4ddbf7a..321afc4 100644 --- a/src/fetch.ts +++ b/src/fetch.ts @@ -40,9 +40,9 @@ export interface FetchOptions extends Omi } export interface $Fetch { - (request: FetchRequest, opts?: FetchOptions): Promise> - raw(request: FetchRequest, opts?: FetchOptions): Promise>> - create(defaults: FetchOptions): $Fetch + (request: FetchRequest, opts?: FetchOptions): Promise> + raw (request: FetchRequest, opts?: FetchOptions): Promise>> + create (defaults: FetchOptions): $Fetch } // https://developer.mozilla.org/en-US/docs/Web/HTTP/Status @@ -156,13 +156,15 @@ export function createFetch (globalOptions: CreateFetchOptions): $Fetch { await ctx.options.onResponse(ctx as any) } - if (!ctx.response.ok) { + if (ctx.response.status >= 400 && ctx.response.status < 600) { if (ctx.options.onResponseError) { await ctx.options.onResponseError(ctx as any) } + + return onError(ctx) } - return ctx.response.ok ? ctx.response : onError(ctx) + return ctx.response } const $fetch = function $fetch (request, opts) {