2020-12-24 16:37:38 -09:00
|
|
|
const baseURL = "/api/";
|
|
|
|
import axios from "axios";
|
|
|
|
import store from "../store/store";
|
|
|
|
|
2021-01-01 16:51:55 -09:00
|
|
|
// look for data.snackbar in response
|
2020-12-24 16:37:38 -09:00
|
|
|
function processResponse(response) {
|
2021-01-01 16:51:55 -09:00
|
|
|
try {
|
2020-12-24 16:37:38 -09:00
|
|
|
store.commit("setSnackBar", {
|
|
|
|
text: response.data.snackbar.text,
|
|
|
|
type: response.data.snackbar.type,
|
|
|
|
});
|
2021-01-01 16:51:55 -09:00
|
|
|
} catch (err) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return;
|
2020-12-24 16:37:38 -09:00
|
|
|
}
|
|
|
|
|
|
|
|
const apiReq = {
|
|
|
|
post: async function(url, data) {
|
|
|
|
let response = await axios.post(url, data).catch(function(error) {
|
|
|
|
if (error.response) {
|
|
|
|
console.log("Error");
|
|
|
|
processResponse(error.response);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
processResponse(response);
|
|
|
|
return response;
|
|
|
|
},
|
|
|
|
|
|
|
|
get: async function(url, data) {
|
|
|
|
let response = await axios.get(url, data).catch(function(error) {
|
|
|
|
if (error.response) {
|
|
|
|
processResponse(error.response);
|
|
|
|
return;
|
|
|
|
} else return;
|
|
|
|
});
|
|
|
|
// processResponse(response);
|
|
|
|
return response;
|
|
|
|
},
|
|
|
|
|
|
|
|
delete: async function(url, data) {
|
|
|
|
let response = await axios.delete(url, data).catch(function(error) {
|
|
|
|
if (error.response) {
|
|
|
|
processResponse(error.response);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
processResponse(response);
|
|
|
|
return response;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export { apiReq };
|
|
|
|
export { baseURL };
|