title: fetch returns SyntaxError: Unexpected token T in JSON at position 0
body: <p>I'm trying to use the Javascript fetch method, however, it does not seem to work asynchronously.</p>
  <p>Here's my code:</p>
  <pre><code>fetch(`${global.URL}${url}`, requestConfig)
    .then(res =&gt; res.json())
    .then(res =&gt; {
      console.log('response', res);
      return res;
    })
    .catch(error =&gt; {
      console.log('error: ', error)
    })
  </code></pre>
  <p>I get the following error 70% of the time, then the other 30%, a valid response is received, when I save the file and it re-renders, it sometimes works.</p>
  <pre><code>error:  SyntaxError: Unexpected token T in JSON at position 0
      at parse (&lt;anonymous&gt;)
      at tryCallOne (core.js:37)
      at core.js:123
      at JSTimers.js:277
      at _callTimer (JSTimers.js:135)
      at _callImmediatesPass (JSTimers.js:183)
      at Object.callImmediates (JSTimers.js:446)
      at MessageQueue.__callImmediates (MessageQueue.js:396)
      at MessageQueue.js:144
      at MessageQueue.__guard (MessageQueue.js:373)
  </code></pre>
  <p>I've tried calling it inside and async/await function but it does not help.</p>
  <p>EDIT 1:</p>
  <p>this is how I make my requests</p>
  <pre><code>const authenticityToken = global.TOKEN
  
  const query = (url, config) =&gt; {
    const requestConfig = {
      credentials: 'same-origin',
      ...config,
      headers: {
        'X-Requested-With': 'XMLHttpRequest',
        'Content-Type': 'application/json',
        Accept: 'application/json',
        Authorization: authenticityToken,
      },
    }
  
    return fetch(`${global.URL}${url}`, requestConfig)
    .then(res =&gt; res.json())
    .then(res =&gt; {
      console.log('response', res);
      return res;
    })
    .catch(error =&gt; {
      console.log('error: ', error)
    })
    // .then(handleResponseError)
  }
  
  export const get = (url, data) =&gt;
    query(data ? `${url}?${stringify(data)}` : url)
  
  export function fetchUser() {
    return (
      get('/api/v3/me/')
    )
  }
  </code></pre>
  <p>Then I call the function inside my component like so:</p>
  <pre><code>  const fetchUserAction = () =&gt; {
      fetchUser()
      .then((response) =&gt; {
        if(response) setUser(response.data)
      })
    }
  
    useEffect(() =&gt; {
      fetchUserAction()
    }, [])
  </code></pre>