Skip to content

Commit

Permalink
refactor: add from method to custom errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tien committed Jun 11, 2024
1 parent e871b85 commit 9460ad3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
18 changes: 15 additions & 3 deletions packages/core/src/errors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
export class ReDotError extends Error {}
export class ReDotError extends Error {
static from<T>(error: T, message?: string): ReDotError {
return new ReDotError(message, { cause: error });
}
}

export class QueryError extends ReDotError {}
export class QueryError extends ReDotError {
static override from<T>(error: T, message?: string): QueryError {
return new QueryError(message, { cause: error });
}
}

export class MutationError extends ReDotError {}
export class MutationError extends ReDotError {
static override from<T>(error: T, message?: string): MutationError {
return new MutationError(message, { cause: error });
}
}
2 changes: 1 addition & 1 deletion packages/react/src/hooks/useMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const useMutation = <
.subscribe({
next: setState,
error: (error) => {
setState(new MutationError(undefined, { cause: error }));
setState(MutationError.from(error));
reject(error);
},
complete: resolve,
Expand Down

0 comments on commit 9460ad3

Please sign in to comment.