mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-11-05 03:33:19 -05:00
feature/recipe-patch-improvements (#382)
* automated docs update * recipe rating component * recipe partial updates - closes #25 * use Vue.delete to update store * format * arrow functions * fix tests * format * initial context menu * localize * add confirmation dialog * context menu * fix bare exception * update line length * format all file with prettier * update changelog * download as json * update python dependencies * update javascript dependencies Co-authored-by: hay-kot <hay-kot@pm.me>
This commit is contained in:
@@ -3,18 +3,16 @@ import axios from "axios";
|
||||
import { store } from "../store";
|
||||
import utils from "@/utils";
|
||||
|
||||
axios.defaults.headers.common[
|
||||
"Authorization"
|
||||
] = `Bearer ${store.getters.getToken}`;
|
||||
axios.defaults.headers.common["Authorization"] = `Bearer ${store.getters.getToken}`;
|
||||
|
||||
function handleError(error, getText) {
|
||||
if(getText) {
|
||||
if (getText) {
|
||||
utils.notify.error(getText(error.response));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function handleResponse(response, getText) {
|
||||
if(response && getText) {
|
||||
if (response && getText) {
|
||||
const successText = getText(response);
|
||||
utils.notify.success(successText);
|
||||
}
|
||||
@@ -31,26 +29,36 @@ function defaultSuccessText(response) {
|
||||
|
||||
const apiReq = {
|
||||
post: async function(url, data, getErrorText = defaultErrorText, getSuccessText) {
|
||||
const response = await axios.post(url, data).catch(function(error) { handleError(error, getErrorText) });
|
||||
return handleResponse(response, getSuccessText);
|
||||
},
|
||||
|
||||
put: async function(url, data, getErrorText = defaultErrorText, getSuccessText) {
|
||||
const response = await axios.put(url, data).catch(function(error) { handleError(error, getErrorText) });
|
||||
const response = await axios.post(url, data).catch(function(error) {
|
||||
handleError(error, getErrorText);
|
||||
});
|
||||
return handleResponse(response, getSuccessText);
|
||||
},
|
||||
|
||||
|
||||
put: async function(url, data, getErrorText = defaultErrorText, getSuccessText) {
|
||||
const response = await axios.put(url, data).catch(function(error) {
|
||||
handleError(error, getErrorText);
|
||||
});
|
||||
return handleResponse(response, getSuccessText);
|
||||
},
|
||||
|
||||
patch: async function(url, data, getErrorText = defaultErrorText, getSuccessText) {
|
||||
const response = await axios.patch(url, data).catch(function(error) { handleError(error, getErrorText) });
|
||||
const response = await axios.patch(url, data).catch(function(error) {
|
||||
handleError(error, getErrorText);
|
||||
});
|
||||
return handleResponse(response, getSuccessText);
|
||||
},
|
||||
|
||||
get: function(url, data, getErrorText = defaultErrorText) {
|
||||
return axios.get(url, data).catch(function(error) { handleError(error, getErrorText) });
|
||||
return axios.get(url, data).catch(function(error) {
|
||||
handleError(error, getErrorText);
|
||||
});
|
||||
},
|
||||
|
||||
delete: async function(url, data, getErrorText = defaultErrorText, getSuccessText = defaultSuccessText ) {
|
||||
const response = await axios.delete(url, data).catch( function(error) { handleError(error, getErrorText) } );
|
||||
delete: async function(url, data, getErrorText = defaultErrorText, getSuccessText = defaultSuccessText) {
|
||||
const response = await axios.delete(url, data).catch(function(error) {
|
||||
handleError(error, getErrorText);
|
||||
});
|
||||
return handleResponse(response, getSuccessText);
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user