Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add status and statusText to fetch errors #152

Merged
merged 6 commits into from
Oct 27, 2022
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export class FetchError<T = any> extends Error {
request?: FetchRequest
response?: FetchResponse<T>
data?: T
status?: number
statusText?: string
danielroe marked this conversation as resolved.
Show resolved Hide resolved
}

export function createFetchError<T = any> (request: FetchRequest, error?: Error, response?: FetchResponse<T>): FetchError<T> {
Expand All @@ -21,6 +23,8 @@ export function createFetchError<T = any> (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 } })
pi0 marked this conversation as resolved.
Show resolved Hide resolved

return fetchError
}