0

I am working to implement my own Chrome Plugin. I have created a fetch function which should return JSON from the API. However it return a promise object with status of resolved and values. I am trying to just get plain JSON object out of API with fetch.

class _UTILS {
    static getContent(path) {
        const data = fetch(path)
            .then((response) => {
                return response.json().then((json) => {
                    return json;
                })
            }).catch((err) => {
                console.log("Request Problem: ", err);
            });
        console.log(data);

    }
}
NashPL
  • 461
  • 1
  • 4
  • 19
  • 1
    `getContent` **can't** *return* the content. It can only return a promise of it (or provide it to a callback etc.). See the linked question's answers for more. – T.J. Crowder Dec 28 '18 at 14:51
  • Thanks. I know I am missing the OK check in the code. I was going to add it at the end after i proven that it works. – NashPL Dec 28 '18 at 14:56
  • 1
    Yeah i get you. I have added the ok check now. Thanks for help i got it working :) – NashPL Dec 28 '18 at 15:17

0 Answers0