From 40922902cc1393de3d470cc0deb06f31cdbe3dd9 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Thu, 27 Oct 2022 10:35:28 +0200 Subject: [PATCH 1/6] feat: add `statusCode` to fetch errors --- src/error.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/error.ts b/src/error.ts index 6896ef6..4e01225 100644 --- a/src/error.ts +++ b/src/error.ts @@ -21,6 +21,7 @@ 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, 'statusCode', { get () { return response && response.status } }) return fetchError } From 177d62f939ff9fa95d465bc51b8dddcfc80bb924 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Thu, 27 Oct 2022 10:43:49 +0200 Subject: [PATCH 2/6] feat: add `statusMessage` as well --- src/error.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/error.ts b/src/error.ts index 4e01225..718e081 100644 --- a/src/error.ts +++ b/src/error.ts @@ -22,6 +22,7 @@ export function createFetchError (request: FetchRequest, error?: Error, Object.defineProperty(fetchError, 'response', { get () { return response } }) Object.defineProperty(fetchError, 'data', { get () { return response && response._data } }) Object.defineProperty(fetchError, 'statusCode', { get () { return response && response.status } }) + Object.defineProperty(fetchError, 'statusMessage', { get () { return response && response.statusText } }) return fetchError } From f1b7af3012305e51adbff141434b71d47127076d Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Thu, 27 Oct 2022 10:44:12 +0200 Subject: [PATCH 3/6] fix: add types --- src/error.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/error.ts b/src/error.ts index 718e081..041538c 100644 --- a/src/error.ts +++ b/src/error.ts @@ -5,6 +5,8 @@ export class FetchError extends Error { request?: FetchRequest response?: FetchResponse data?: T + statusCode?: number + statusMessage?: string } export function createFetchError (request: FetchRequest, error?: Error, response?: FetchResponse): FetchError { From d700bdbd4d3fff192b9139b5314298de4a5e7fc0 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Thu, 27 Oct 2022 10:48:08 +0200 Subject: [PATCH 4/6] refactor: rename --- src/error.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/error.ts b/src/error.ts index 041538c..c5e5556 100644 --- a/src/error.ts +++ b/src/error.ts @@ -5,8 +5,8 @@ export class FetchError extends Error { request?: FetchRequest response?: FetchResponse data?: T - statusCode?: number - statusMessage?: string + status?: number + statusText?: string } export function createFetchError (request: FetchRequest, error?: Error, response?: FetchResponse): FetchError { @@ -23,8 +23,8 @@ 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, 'statusCode', { get () { return response && response.status } }) - Object.defineProperty(fetchError, 'statusMessage', { get () { return response && response.statusText } }) + Object.defineProperty(fetchError, 'status', { get () { return response && response.status } }) + Object.defineProperty(fetchError, 'statusText', { get () { return response && response.statusText } }) return fetchError } From 5a92c4fb41c6e3e977cd8a9e1bba7699efe6b7ca Mon Sep 17 00:00:00 2001 From: pooya parsa Date: Thu, 27 Oct 2022 11:07:32 +0200 Subject: [PATCH 5/6] Update src/error.ts Co-authored-by: Daniel Roe --- src/error.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/error.ts b/src/error.ts index c5e5556..c39c0d3 100644 --- a/src/error.ts +++ b/src/error.ts @@ -25,6 +25,8 @@ export function createFetchError (request: FetchRequest, error?: Error, 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 } From 7170bf7ca59d27a298c146157d32d8e1ca3939f4 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Thu, 27 Oct 2022 11:07:58 +0200 Subject: [PATCH 6/6] Update src/error.ts --- src/error.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/error.ts b/src/error.ts index c39c0d3..81db881 100644 --- a/src/error.ts +++ b/src/error.ts @@ -7,6 +7,8 @@ export class FetchError extends Error { data?: T status?: number statusText?: string + statusCode?: number + statusMessage?: string } export function createFetchError (request: FetchRequest, error?: Error, response?: FetchResponse): FetchError {