0
votes

I have this issue in the yellowBox (React Native)

Possible Unhandled Promise Rejection (id: 2): TypeError: _petition.default.getCategory is not a function TypeError: _petition.default.getCategory is not a function at api$ (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:104932:33) at tryCatch (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:26922:19) at Generator.invoke [as _invoke] (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:27098:24) at Generator.prototype. [as next] (http://localhost:8081/index.bundle?........

and my code of the petition is the following:

class petition {
  async getCategories() {
    try {
      const response = await fetch('https://yts.mx/api/v2/list_movies.json');
      const data = await response.json();
      return data.data.movies;
    } catch (error) {
      console.log(`error ocurred:${error}`);
    }
  }
  async getRecommendations(id) {
    try {
      const response = await fetch(
        `https://yts.mx/api/v2/movie_suggestions.json?movie_id=${id}`,
      );
      const rawData = await response.json();
      return rawData.data.movies;
    } catch (error) {
      console.log(`error ocurred (${error})`);
    }
  }
}

export default new petition();
1
I can't see any getCategory function, or function call. Where is that defined and being called?Jayce444
Remember to re-throw errors from catch handlers, otherwise they will remain caught and callers will be returned a promise that will follow its success path even when an error has occurred. Even better, don't catch in low level worker functions. Leave all catching/logging to higher levels.Roamer-1888
export default new petition(); .... odd pattern - is there a reason for it?Roamer-1888

1 Answers

0
votes

alright I had an extra function call, my error sorry and thank you to everyone