Handle api error json (#18)

* Handle api error json

* Fix get vehicles error handling
Update .env.template
This commit is contained in:
John Wu
2021-03-17 15:11:41 -07:00
committed by GitHub
parent 2e1f4a7a7c
commit bf401e68eb
10 changed files with 69 additions and 47 deletions

14
src/utils/http.js Normal file
View File

@@ -0,0 +1,14 @@
export const getAuthHeaderOptions = (token) => ({
"Authorization": `Bearer ${token}`,
});
export const fetchRespHandler = (response) => {
if (response.ok) return response.json();
return response.text()
.then((text) => JSON.parse(text))
.catch((e) => ({
error: response.statusText,
message: `${response.status} ${response.statusText}`,
}))
}