-
-
Notifications
You must be signed in to change notification settings - Fork 436
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- reuse `fetchSafe` - omit `github-actions[bot]` from contributors list
- Loading branch information
1 parent
dc805db
commit 0b0b95a
Showing
3 changed files
with
13 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
export function safeResJson<T>(res: Response) { | ||
if (res.ok) return res.json() as Promise<T>; | ||
export async function fetchSafe<T>(endpoint: string): Promise<T> { | ||
const response = await fetch(endpoint); | ||
|
||
throw new Error("Internal server error!"); | ||
if (!response.ok) { | ||
throw new Error("Internal server error!"); | ||
} | ||
|
||
return response.json(); | ||
} |