From 784a7c0524a60406b0ba09055502107ef57ef5c9 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Thu, 27 Oct 2022 11:08:33 +0200 Subject: [PATCH] feat: add `status` and `statusText` to fetch errors (#152) --- src/error.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/error.ts b/src/error.ts index 6896ef6..81db881 100644 --- a/src/error.ts +++ b/src/error.ts @@ -5,6 +5,10 @@ export class FetchError extends Error { request?: FetchRequest response?: FetchResponse data?: T + status?: number + statusText?: string + statusCode?: number + statusMessage?: string } export function createFetchError (request: FetchRequest, error?: Error, response?: FetchResponse): FetchError { @@ -21,6 +25,10 @@ export function createFetchError (request: FetchRequest, error?: Error, Object.defineProperty(fetchError, 'request', { get () { return request } }) Object.defineProperty(fetchError, 'response', { get () { return response } }) Object.defineProperty(fetchError, 'data', { get () { return response && response._data } }) + Object.defineProperty(fetchError, 'status', { get () { return response && response.status } }) + Object.defineProperty(fetchError, 'statusText', { get () { return response && response.statusText } }) + Object.defineProperty(fetchError, 'statusCode', { get () { return response && response.status } }) + Object.defineProperty(fetchError, 'statusMessage', { get () { return response && response.statusText } }) return fetchError }