-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
39 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
type ErrorType = 'BadRequestError' | 'NotFoundError' | 'RedirectError' | ||
|
||
interface Extension { | ||
type: ErrorType | ||
status: number | ||
} | ||
|
||
class FastStoreError<T extends Extension = Extension> extends Error { | ||
constructor(public extensions: T, message?: string) { | ||
super(message) | ||
this.name = 'FastStoreError' | ||
} | ||
} | ||
|
||
export class BadRequestError extends FastStoreError { | ||
constructor(message?: string) { | ||
super({ status: 400, type: 'BadRequestError' }, message) | ||
} | ||
} | ||
|
||
export class NotFoundError extends FastStoreError { | ||
constructor(message?: string) { | ||
super({ status: 404, type: 'NotFoundError' }, message) | ||
} | ||
} | ||
|
||
export const isFastStoreError = (error: any): error is FastStoreError => | ||
error?.name === 'FastStoreError' | ||
|
||
export const isNotFoundError = (error: any): error is NotFoundError => | ||
error?.extensions?.type === 'NotFoundError' | ||
|
||
export const isBadRequestError = (error: any): error is BadRequestError => | ||
error?.extensions?.type === 'BadRequestError' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.