-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add error handling for external api requests
- Loading branch information
1 parent
16e7905
commit cfc41e6
Showing
5 changed files
with
51 additions
and
3 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
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,29 @@ | ||
import type { Dictionary } from "../../dictionaries"; | ||
|
||
export type ErrorType = keyof Dictionary["errors"]; | ||
|
||
export interface OkResponse<T> { | ||
ok: true; | ||
error: null; | ||
data: T; | ||
} | ||
|
||
export interface ErrorResponse { | ||
ok: false; | ||
error: ErrorType; | ||
data: null; | ||
} | ||
|
||
export type ApiResponse<T> = OkResponse<T> | ErrorResponse; | ||
|
||
export const ok = <T>(data: T): OkResponse<T> => ({ | ||
ok: true, | ||
error: null, | ||
data, | ||
}); | ||
|
||
export const err = (error: ErrorType): ErrorResponse => ({ | ||
ok: false, | ||
error, | ||
data: null, | ||
}); |
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