jonasschmedtmann / complete-javascript-course

Starter files, final projects, and FAQ for my Complete JavaScript course
https://www.udemy.com/the-complete-javascript-course/?couponCode=C3GITHUB10
15.69k stars 16.81k forks source link

Forkify API Error: Request timed out #386

Open songhetian opened 1 year ago

songhetian commented 1 year ago

I've been learning with your course, and I find it amazing and all has been going smooth. Everything was fine before I went to bed last night, however, when I woke up this morning to continue with building the Forkify App, it keeps failing to generate data from the Forkify API. I visited the demo site (forkify-v2.netlify.app) and the same issue persisted. Please check kindly look into it.

obiboss commented 9 months ago

when i try to visit this site https://forkify-api.herokuapp.com/api/v2/recipes/ i receive an error message { "status": "error", "message": "Something went very wrong!" } I would like to know how to resolve this

akozdev commented 9 months ago

The /recipes endpoint has a required search parameter, so in order to make it work, you will need to pass some search query, for example, /recipes?search=pizza.

I think the API should respond with a better message, and a different Http code in this case. We'll change it in the future.

obiboss commented 9 months ago

Thanks akozdev i noticed it worked on the browser but I didn't think to try it out in the code as it looked a bit weird

obiboss commented 9 months ago

However the goal was to sendJSON(url, recipe) but i get the error message so if i were to use this /recipes?search=pizza example i would get a list of pizza and not be able to send my own data

obiboss commented 9 months ago

The /recipes endpoint has a required search parameter, so in order to make it work, you will need to pass some search query, for example, /recipes?search=pizza.

I think the API should respond with a better message, and a different Http code in this case. We'll change it in the future. Thanks for your response However the goal was to sendJSON(url, recipe) but i get the error message so if i were to use this /recipes?search=pizza example i would get a list of pizza and not be able to send my own data

akozdev commented 9 months ago

To upload a new recipe, send a POST request to the /recipes endpoint. In this case, you only need to provide your API key in the params, like this /recipes?key=<your key> because POST requests are handled differently on this endpoint.

The sendJSON() function should already be configured to send POST requests

const fetchPromise = fetch(url, {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify(uploadData),
    });
obiboss commented 9 months ago

To upload a new recipe, send a POST request to the /recipes endpoint. In this case, you only need to provide your API key in the params, like this /recipes?key=<your key> because POST requests are handled differently on this endpoint.

The sendJSON() function should already be configured to send POST requests

const fetchPromise = fetch(url, {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify(uploadData),
    });

error

image

error I am still getting error

helpers.js:33

   GET https://forkify-api.herokuapp.com/api/v2/recipes?key=924ac711-1d3b-4ccf-8271-2cae6c20e0fb 500 (Internal Server Error)

sendJSON @ helpers.js:33 await in sendJSON (async) uploadRecipe @ model.js:140 controlAddRecipe @ controller.js:96 (anonymous) @ addRecipeView.js:40 controller.js:98 Error: Something went very wrong! 500 at sendJSON (helpers.js:35:24) at async Object.uploadRecipe (model.js:140:18) at async controlAddRecipe (controller.js:96:5)

obiboss commented 9 months ago

I have seen the error an unused variable i was using fetch(url) when i had created a variable named fetchPro to store it already. Thanks a lot it was really helpful

akozdev commented 9 months ago

You're welcome!