fetch() unexpected end of input

前端 未结 5 2259
暖寄归人
暖寄归人 2020-11-30 02:34

I am using fetch() to grab data from api server. My error looks like this:

Uncaught (in promise) SyntaxError: Unexpected end of input at 
  fetch.then.blob.
         


        
5条回答
  •  萌比男神i
    2020-11-30 02:48

    Lots of good responses but I chose this:

          const response = await fetch(url, {
            method: 'GET',
            headers: {
              Authorization: 'Bearer ' + accessToken
            }
          });
          const string = await response.text();
          const json = string === "" ? {} : JSON.parse(string);
          return json;
    

提交回复
热议问题