mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-07-09 03:04:54 -04:00
Bug/fix infinite loop (#512)
* fix infinite loop with safe get method * fix ingredients Co-authored-by: hay-kot <hay-kot@pm.me>
This commit is contained in:
parent
2dc9c8e843
commit
af41b08a60
@ -27,47 +27,88 @@ function defaultSuccessText(response) {
|
|||||||
return response.statusText;
|
return response.statusText;
|
||||||
}
|
}
|
||||||
|
|
||||||
const apiReq = {
|
const requests = {
|
||||||
post: async function(url, data, getErrorText = defaultErrorText, getSuccessText) {
|
/**
|
||||||
const response = await axios.post(url, data).catch(function(error) {
|
*
|
||||||
|
* @param {*} funcCall Callable Axios Function
|
||||||
|
* @param {*} url Destination url
|
||||||
|
* @param {*} data Request Data
|
||||||
|
* @param {*} getErrorText Error Text Function
|
||||||
|
* @param {*} getSuccessText Success Text Function
|
||||||
|
* @returns Object response
|
||||||
|
*/
|
||||||
|
unsafe: async function(funcCall, url, data, getErrorText = defaultErrorText, getSuccessText) {
|
||||||
|
const response = await funcCall(url, data).catch(function(error) {
|
||||||
handleError(error, getErrorText);
|
handleError(error, getErrorText);
|
||||||
return error;
|
|
||||||
});
|
});
|
||||||
return handleResponse(response, getSuccessText);
|
return handleResponse(response, getSuccessText);
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {*} funcCall Callable Axios Function
|
||||||
|
* @param {*} url Destination url
|
||||||
|
* @param {*} data Request Data
|
||||||
|
* @param {*} getErrorText Error Text Function
|
||||||
|
* @param {*} getSuccessText Success Text Function
|
||||||
|
* @returns Array [response, error]
|
||||||
|
*/
|
||||||
|
safe: async function(funcCall, url, data, getErrorText = defaultErrorText, getSuccessText) {
|
||||||
|
const response = await funcCall(url, data).catch(function(error) {
|
||||||
|
handleError(error, getErrorText);
|
||||||
|
return [null, error];
|
||||||
|
});
|
||||||
|
return [handleResponse(response, getSuccessText), null];
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const apiReq = {
|
||||||
|
get: async function(url, getErrorText = defaultErrorText) {
|
||||||
|
return axios.get(url).catch(function(error) {
|
||||||
|
handleError(error, getErrorText);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
getSafe: async function(url) {
|
||||||
|
let error = null;
|
||||||
|
const response = await axios.get(url).catch(e => {
|
||||||
|
error = e;
|
||||||
|
});
|
||||||
|
return [response, error];
|
||||||
|
},
|
||||||
|
|
||||||
|
post: async function(url, data, getErrorText = defaultErrorText, getSuccessText) {
|
||||||
|
return await requests.unsafe(axios.post, url, data, getErrorText, getSuccessText);
|
||||||
|
},
|
||||||
|
|
||||||
|
postSafe: async function(url, data, getErrorText = defaultErrorText, getSuccessText) {
|
||||||
|
return await requests.safe(axios.post, url, data, getErrorText, getSuccessText);
|
||||||
|
},
|
||||||
|
|
||||||
put: async function(url, data, getErrorText = defaultErrorText, getSuccessText) {
|
put: async function(url, data, getErrorText = defaultErrorText, getSuccessText) {
|
||||||
const response = await axios.put(url, data).catch(function(error) {
|
return await requests.unsafe(axios.put, url, data, getErrorText, getSuccessText);
|
||||||
handleError(error, getErrorText);
|
},
|
||||||
return error;
|
|
||||||
});
|
putSafe: async function(url, data, getErrorText = defaultErrorText, getSuccessText) {
|
||||||
return handleResponse(response, getSuccessText);
|
return await requests.safe(axios.put, url, data, getErrorText, getSuccessText);
|
||||||
},
|
},
|
||||||
|
|
||||||
patch: async function(url, data, getErrorText = defaultErrorText, getSuccessText) {
|
patch: async function(url, data, getErrorText = defaultErrorText, getSuccessText) {
|
||||||
const response = await axios.patch(url, data).catch(function(error) {
|
return await requests.unsafe(axios.patch, url, data, getErrorText, getSuccessText);
|
||||||
handleError(error, getErrorText);
|
|
||||||
return error;
|
|
||||||
});
|
|
||||||
return handleResponse(response, getSuccessText);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
get: async function(url, data, getErrorText = defaultErrorText) {
|
patchSafe: async function(url, data, getErrorText = defaultErrorText, getSuccessText) {
|
||||||
return axios.get(url, data).catch(function(error) {
|
return await requests.safe(axios.patch, url, data, getErrorText, getSuccessText);
|
||||||
handleError(error, getErrorText);
|
|
||||||
return error;
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
delete: async function(url, data, getErrorText = defaultErrorText, getSuccessText = defaultSuccessText) {
|
delete: async function(url, data, getErrorText = defaultErrorText, getSuccessText = defaultSuccessText) {
|
||||||
const response = await axios.delete(url, data).catch(function(error) {
|
return await requests.unsafe(axios.delete, url, data, getErrorText, getSuccessText);
|
||||||
handleError(error, getErrorText);
|
|
||||||
return error;
|
|
||||||
});
|
|
||||||
return handleResponse(response, getSuccessText);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
async download(url) {
|
deleteSafe: async function(url, data, getErrorText = defaultErrorText, getSuccessText = defaultSuccessText) {
|
||||||
|
return await requests.unsafe(axios.delete, url, data, getErrorText, getSuccessText);
|
||||||
|
},
|
||||||
|
|
||||||
|
download: async function(url) {
|
||||||
const response = await this.get(url);
|
const response = await this.get(url);
|
||||||
const token = response.data.fileToken;
|
const token = response.data.fileToken;
|
||||||
|
|
||||||
|
@ -35,10 +35,8 @@ export const recipeAPI = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
async requestDetails(recipeSlug) {
|
async requestDetails(recipeSlug) {
|
||||||
const response = await apiReq.get(API_ROUTES.recipesRecipeSlug(recipeSlug));
|
const response = await apiReq.getSafe(API_ROUTES.recipesRecipeSlug(recipeSlug));
|
||||||
if (response.response) {
|
console.log(response);
|
||||||
return response.response;
|
|
||||||
}
|
|
||||||
return response;
|
return response;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -12,12 +12,6 @@
|
|||||||
|
|
||||||
<v-form @submit.prevent="login">
|
<v-form @submit.prevent="login">
|
||||||
<v-card-text>
|
<v-card-text>
|
||||||
<v-text-field
|
|
||||||
v-if="!options.isLoggingIn"
|
|
||||||
v-model="user.name"
|
|
||||||
prepend-icon="person"
|
|
||||||
:label="$t('general.name')"
|
|
||||||
></v-text-field>
|
|
||||||
<v-text-field
|
<v-text-field
|
||||||
v-model="user.email"
|
v-model="user.email"
|
||||||
prepend-icon="mdi-email"
|
prepend-icon="mdi-email"
|
||||||
@ -35,12 +29,10 @@
|
|||||||
@click:append="showPassword = !showPassword"
|
@click:append="showPassword = !showPassword"
|
||||||
></v-text-field>
|
></v-text-field>
|
||||||
<v-card-actions>
|
<v-card-actions>
|
||||||
<v-btn v-if="options.isLoggingIn" color="primary" block="block" type="submit"
|
<v-btn v-if="options.isLoggingIn" color="primary" block large type="submit">{{ $t("user.sign-in") }} </v-btn>
|
||||||
>{{ $t("user.sign-in") }}
|
|
||||||
</v-btn>
|
|
||||||
</v-card-actions>
|
</v-card-actions>
|
||||||
|
|
||||||
<v-alert v-if="error" outlined class="mt-3 mb-0" type="error">
|
<v-alert v-if="error" class="mt-3 mb-0" type="error">
|
||||||
{{ $t("user.could-not-validate-credentials") }}
|
{{ $t("user.could-not-validate-credentials") }}
|
||||||
</v-alert>
|
</v-alert>
|
||||||
</v-card-text>
|
</v-card-text>
|
||||||
|
@ -192,10 +192,12 @@ export default {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await api.recipes.requestDetails(this.currentRecipe);
|
const [response, error] = await api.recipes.requestDetails(this.currentRecipe);
|
||||||
console.log("View Response", { response });
|
|
||||||
if (response.status === 401) router.push(`/login`);
|
if (error) {
|
||||||
if (response.status === 404) return;
|
if (error.response.status === 401) router.push(`/login`);
|
||||||
|
if (error.response.status === 404) router.push("/page-not-found");
|
||||||
|
}
|
||||||
|
|
||||||
this.recipeDetails = response.data;
|
this.recipeDetails = response.data;
|
||||||
this.skeleton = false;
|
this.skeleton = false;
|
||||||
|
@ -198,12 +198,18 @@ export default {
|
|||||||
this.$refs.searchRecipe.open();
|
this.$refs.searchRecipe.open();
|
||||||
},
|
},
|
||||||
async importIngredients(selected) {
|
async importIngredients(selected) {
|
||||||
const response = await api.recipes.requestDetails(selected.slug);
|
const [response, error] = await api.recipes.requestDetails(selected.slug);
|
||||||
|
console.log(response);
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
|
||||||
const recipe = response.data;
|
const recipe = response.data;
|
||||||
|
|
||||||
const ingredients = recipe.recipeIngredient.map(x => ({
|
const ingredients = recipe.recipeIngredient.map(x => ({
|
||||||
title: "",
|
title: "",
|
||||||
text: x,
|
text: x.note,
|
||||||
quantity: 1,
|
quantity: 1,
|
||||||
checked: false,
|
checked: false,
|
||||||
}));
|
}));
|
||||||
|
@ -18,6 +18,7 @@ export const routes = [
|
|||||||
...mealRoutes,
|
...mealRoutes,
|
||||||
...recipeRoutes,
|
...recipeRoutes,
|
||||||
|
|
||||||
|
{ path: "/page-not-found", component: Page404 },
|
||||||
{ path: "*", component: Page404 },
|
{ path: "*", component: Page404 },
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -31,7 +32,7 @@ const router = new VueRouter({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const DEFAULT_TITLE = "Mealie";
|
const DEFAULT_TITLE = "Mealie";
|
||||||
const TITLE_SEPARATOR = "🍴";
|
const TITLE_SEPARATOR = "|";
|
||||||
const TITLE_SUFFIX = " " + TITLE_SEPARATOR + " " + DEFAULT_TITLE;
|
const TITLE_SUFFIX = " " + TITLE_SEPARATOR + " " + DEFAULT_TITLE;
|
||||||
router.afterEach(to => {
|
router.afterEach(to => {
|
||||||
Vue.nextTick(async () => {
|
Vue.nextTick(async () => {
|
||||||
|
@ -26,7 +26,8 @@ export const recipeRoutes = [
|
|||||||
component: ViewRecipe,
|
component: ViewRecipe,
|
||||||
meta: {
|
meta: {
|
||||||
title: async route => {
|
title: async route => {
|
||||||
const response = await api.recipes.requestDetails(route.params.recipe);
|
const [response, error] = await api.recipes.requestDetails(route.params.recipe);
|
||||||
|
if (error) console.log({ error });
|
||||||
const recipe = response.data;
|
const recipe = response.data;
|
||||||
if (recipe && recipe.name) return recipe.name;
|
if (recipe && recipe.name) return recipe.name;
|
||||||
else return null;
|
else return null;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user