title: SyntaxError: Unexpected token B in JSON at position 0 - JSON Rest API
body: <p>I'm working with a JSON rest API that has the following response:</p>
  <pre><code>// response
  [
    {
      id: 1,
      userId: 1,
      start: &quot;2018-01-01 10:15&quot;,
      finish: &quot;2018-01-01 12:20&quot;,
      breakLength: 30
    },
    {
      id: 2,
      userId: 1,
      start: &quot;2018-01-02 10:15&quot;,
      finish: &quot;2018-01-02 18:20&quot;,
      breakLength: 45
    }
  ];
  </code></pre>
  <p>See below for code. Like my other functions, I am requesting a GET using <code>fetch()</code>. However, sometimes this function when called requests and responds with a <code>200</code>, and sometimes it responds with a <code>400 bad request</code>(<em>Uncaught (in promise) SyntaxError: Unexpected token B in JSON at position 0</em>) It seems very random when it happens. My server which the JSON Rest API is on is <code>localhost:3000</code> and my application is on <code>localhost:3001</code>. I have used this same method for other JSON requests and they work perfectly. I am not sure why this one is having trouble? Thanks for your help!</p>
  <p><strong>Update</strong>: It seems as though the last <code>Promise.all</code>, <code>setState</code> is not being executed. The program is crashing on line <code>.then(response =&gt; response.json())</code> in <code>promise3</code>.</p>
  <p><strong>Updated Code</strong>:</p>
  <pre><code>    getShifts = (sessionId) =&gt; {
          return fetch(&quot;http://localhost:3000/shifts&quot;, {
            method: &quot;GET&quot;,
            headers: {
              &quot;Accept&quot;: &quot;application/json&quot;,
              &quot;Content-Type&quot;: &quot;application/json&quot;,
              &quot;Authorization&quot;: sessionId
            }
          });
        };
  
  
  callbackSessionId = (sessionId) =&gt; {
      let promise1 = this.fetchUserAttributes(sessionId)
          .then(response =&gt; response.json())
          .then(json =&gt; this.setState({
              userAttributes: json
          }));
      Promise.all([promise1]).then(() =&gt; {
          let promise2 = this.getOrganisations(sessionId)
              .then(response =&gt; response.json())
              .then(json =&gt; this.setState({
                  organisations: json
              }));
          let promise3 = this.getShifts(sessionId)
              .then(response =&gt; response.json())
              .then(json =&gt; this.setState({
                  shifts: json
              }));
          // this.setState({
          //     sessionId: sessionId
          // });
          Promise.all([promise2, promise3]).then(() =&gt; {
              this.setState({
                  sessionId: sessionId
              });
          });
      });
  };
  </code></pre>