Handle api error json (#18)
* Handle api error json * Fix get vehicles error handling Update .env.template
This commit is contained in:
@@ -1,20 +1,20 @@
|
||||
import axios from 'axios';
|
||||
import { getAuthHeaderOptions, fetchRespHandler } from "../utils/http"
|
||||
|
||||
const API_ENDPOINT = process.env.REACT_APP_UPLOAD_SERVICE_URL || "https://gw-dev.fiskerdps.com/ota_update";
|
||||
|
||||
const getOptions = (token) => ({
|
||||
headers: {
|
||||
"Authorization": `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
|
||||
const vehiclesAPI = {
|
||||
getVehicles: async (search, token) => {
|
||||
return axios.get(`${API_ENDPOINT}/vehicles`, getOptions(token));
|
||||
},
|
||||
addVehicle: async (vehicle, token) => {
|
||||
return axios.post(`${API_ENDPOINT}/vehicle`, vehicle, getOptions(token));
|
||||
}
|
||||
addVehicle: async (vehicle, token) => fetch(`${API_ENDPOINT}/vehicle`, {
|
||||
method: "POST",
|
||||
headers: Object.assign({ "Content-Type": "application/json" }, getAuthHeaderOptions(token)),
|
||||
body: JSON.stringify(vehicle),
|
||||
})
|
||||
.then(fetchRespHandler),
|
||||
getVehicles: async (search, token) => fetch(`${API_ENDPOINT}/vehicles`, {
|
||||
method: "GET",
|
||||
headers: Object.assign({ "Content-Type": "application/json" }, getAuthHeaderOptions(token)),
|
||||
|
||||
})
|
||||
.then(fetchRespHandler)
|
||||
};
|
||||
|
||||
export default vehiclesAPI;
|
||||
|
||||
Reference in New Issue
Block a user