Handle api error json (#18)
* Handle api error json * Fix get vehicles error handling Update .env.template
This commit is contained in:
14
src/utils/http.js
Normal file
14
src/utils/http.js
Normal 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}`,
|
||||
}))
|
||||
}
|
||||
Reference in New Issue
Block a user