mirror of
https://github.com/hay-kot/mealie.git
synced 2025-07-06 13:02:27 -07:00
init 2
This commit is contained in:
commit
beed8576c2
137 changed files with 40218 additions and 0 deletions
51
frontend/src/api/api-utils.js
Normal file
51
frontend/src/api/api-utils.js
Normal file
|
@ -0,0 +1,51 @@
|
|||
const baseURL = "/api/";
|
||||
import axios from "axios";
|
||||
import store from "../store/store";
|
||||
|
||||
function processResponse(response) {
|
||||
if (("data" in response) & ("snackbar" in response.data)) {
|
||||
store.commit("setSnackBar", {
|
||||
text: response.data.snackbar.text,
|
||||
type: response.data.snackbar.type,
|
||||
});
|
||||
} else return;
|
||||
}
|
||||
|
||||
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 };
|
Loading…
Add table
Add a link
Reference in a new issue