New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError (Error): Cannot read properties of undefined (reading 'nutrients') #47
Comments
This is the full stack trace for reference:
And this is the offending line in var _a = recipe.nutrition, nutrients = _a.nutrients, ingredients = _a.ingredients; |
The const recipes = recipeResponse.data; And I believe this causes let recipe: RecipeResponse;
if (recipes.hasOwnProperty("results")) {
recipe = (recipes as SearchResponse).results[0];
} else {
recipe = recipes as RecipeResponse;
}
const { nutrients, ingredients } = recipe.nutrition;
|
This could be an Axios bug. This is the output of
And this is the output on my local machine:
So it's working on Axios 1.1.2, but not 1.2.0. Guess I didn't update all my dependencies. 😅 Also, my node version is v16.16.0, while Docker's version is v18.12.1, in case that makes a difference. |
Yep, I was right, this is due to a bug in Axios 1.2.0: axios/axios#5328. I can either roll back to 1.1.3 or wait for a patch. The update was done in #44, but I only mocked the API calls while testing. Maybe I should consider testing the real calls? I don't want to do too many tests since I have a limited quota, but this will prevent bugs like these from making it into production. (It will also help if spoonacular changes its schema in the future since we're not in control of the data that's sent back.) |
On all the apps, after clicking the find recipe button, the above error is returned from the server. I wasn't able to reproduce this locally, but I was able to reproduce it on Docker, so I'll look into what the issue is. I recently updated the server to pass the API key in the headers, so could that have something to do with this bug? The API itself seems to be working fine on Postman.
The text was updated successfully, but these errors were encountered: