-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For improved API error handling. If we create many more after this we can add more types based on the base error.
- Loading branch information
Pauline Vos
committed
Nov 13, 2024
1 parent
59b4a59
commit 44cc7c0
Showing
1 changed file
with
42 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
enum ErrorType { | ||
NotAuthorized = "ERROR_NOT_AUTHORIZED", | ||
NotAuthenticated = "ERROR_NOT_AUTHENTICATED", | ||
} | ||
class BadgeHubApiError extends Error { | ||
name: ErrorType; | ||
message: string; | ||
cause: any; | ||
|
||
constructor({ | ||
name, | ||
message, | ||
cause, | ||
}: { | ||
name: ErrorType; | ||
message: string; | ||
cause?: any; | ||
}) { | ||
super(); | ||
this.name = name; | ||
this.message = message; | ||
this.cause = cause; | ||
} | ||
} | ||
const NotAuthenticatedError = ( | ||
message: string = "You are not authenticated" | ||
): BadgeHubApiError => { | ||
return new BadgeHubApiError({ name: ErrorType.NotAuthenticated, message }); | ||
}; | ||
|
||
const NotAuthorizedError = ( | ||
message: string = "You are not authorized" | ||
): BadgeHubApiError => { | ||
return new BadgeHubApiError({ name: ErrorType.NotAuthorized, message }); | ||
}; | ||
|
||
export { | ||
ErrorType, | ||
BadgeHubApiError, | ||
NotAuthorizedError, | ||
NotAuthenticatedError, | ||
}; |