-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: consolidate auth errors and logging
- Loading branch information
1 parent
aef4ab6
commit 390bde8
Showing
4 changed files
with
102 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,49 @@ | ||
import { AppError } from "./types"; | ||
|
||
export const isAppError = (error: any): error is AppError => { | ||
return ( | ||
error && | ||
typeof error === "object" && | ||
"_tag" in error && | ||
typeof error._tag === "string" && | ||
"message" in error && | ||
typeof error.message === "string" | ||
); | ||
}; | ||
|
||
export const isUnauthorizedError = ( | ||
error: any, | ||
): error is { _tag: "UnauthorizedError"; message: string } => { | ||
return isAppError(error) && error._tag === "UnauthorizedError"; | ||
}; | ||
|
||
export const isAuthenticationError = ( | ||
error: any, | ||
): error is { _tag: "AuthenticationError"; message: string } => { | ||
return isAppError(error) && error._tag === "AuthenticationError"; | ||
}; | ||
|
||
export const createUnauthorizedError = (message: string): AppError => ({ | ||
_tag: "UnauthorizedError", | ||
message, | ||
}); | ||
|
||
export const createAuthenticationError = (message: string): AppError => ({ | ||
_tag: "AuthenticationError", | ||
message, | ||
}); | ||
|
||
export const createDatabaseError = (message: string): AppError => ({ | ||
_tag: "DatabaseError", | ||
message, | ||
}); | ||
|
||
export const createValidationError = (message: string): AppError => ({ | ||
_tag: "ValidationError", | ||
message, | ||
}); | ||
|
||
export const createNetworkError = (message: string): AppError => ({ | ||
_tag: "NetworkError", | ||
message, | ||
}); |
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