Skip to content

Commit

Permalink
🏭 Mark errors with a custom class
Browse files Browse the repository at this point in the history
Should solve #79
  • Loading branch information
elbywan committed Jul 3, 2022
1 parent e4dd8aa commit 211c902
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { mix } from "./utils.js"
import type { WretchResponse, WretchErrorCallback } from "./types.js"
import { FETCH_ERROR } from "./constants"

export class WretchError extends Error { }

export interface WretchResponseChain<T, Self = unknown> {
wretchRequest: Wretch<T, Self>,
fetchRequest: Promise<WretchResponse>,
Expand Down Expand Up @@ -91,7 +93,7 @@ export const resolver = <T, Chain>(wretch: Wretch<T, Chain>) => {
})
.then(response => {
if (!response.ok) {
const err = new Error()
const err = new WretchError()
// Enhance the error object
err["cause"] = referenceError
err.stack = err.stack + "\nCAUSE: " + referenceError.stack
Expand Down

0 comments on commit 211c902

Please sign in to comment.