-
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.
Fetch content by ID using REST API from CMS for preview
- Loading branch information
1 parent
f4abad3
commit 40fa516
Showing
5 changed files
with
153 additions
and
8 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
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,10 +1,20 @@ | ||
import unfetch from 'isomorphic-unfetch' | ||
import retry from 'fetch-retry' | ||
|
||
const fetch = (input: RequestInfo, init?: RequestInit) => | ||
export const fetch = (input: RequestInfo, init?: RequestInit) => | ||
retry(unfetch, { | ||
retries: 3, | ||
retryDelay: 500, | ||
})(input, init) | ||
|
||
export default fetch | ||
export const fetchAPI = async <T>(input: RequestInfo, init?: RequestInit) => { | ||
const response = await fetch(input, init) | ||
|
||
if (response.ok) { | ||
return response.json() as Promise<T> | ||
} | ||
|
||
console.error(await response.text()) | ||
|
||
throw new Error(`Error while fetching ${input}`) | ||
} |