-
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.
- Loading branch information
Showing
3 changed files
with
27 additions
and
7 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,9 +1,20 @@ | ||
import useSWR from "swr"; | ||
|
||
const fetcher = (url) => fetch(url, { | ||
credentials: 'include' | ||
}).then(res => res.json()); | ||
|
||
const fetcher = async url => { | ||
const res = await fetch(url, { credentials: 'include' }) | ||
|
||
// If the status code is not in the range 200-299, | ||
// we still try to parse and throw it. | ||
if (!res.ok) { | ||
const error = new Error('An error occurred while fetching the data.') | ||
// Attach extra info to the error object. | ||
error.info = await res.json() | ||
error.status = res.status | ||
throw error | ||
} | ||
|
||
return res.json() | ||
} | ||
export default function useMetadata() { | ||
return useSWR(window.MAPS_API_URL.replace('{MAP_ID}', location.hash.slice(1)), fetcher); | ||
} |