title: Syntax Error Unexpected token DOCTYPE is not valid JSON Next js code
body: <p><strong>I was building a nextjs app that register a retailers and display list of retailers in my fetch-wrapper handleResponse function is not working properly code snippet</strong></p>
  <p>I have a db,json file i tried it with empty json and with data it doesn't work in both way</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>export const fetchWrapper = {
      get,
      post,
      put,
      delete: _delete
  };
  
  async function get(url) {
      const requestOptions = {
          method: 'GET'
      };
      const response = await fetch(url, requestOptions);
      return handleResponse(response);
  }
  
  async function post(url, body) {
      const requestOptions = {
          method: 'POST',
          headers: { 'Content-Type': 'application/json' },
          body: JSON.stringify(body)
      };
      const response = await fetch(url, requestOptions);
      return handleResponse(response);
  }
  
  async function put(url, body) {
      const requestOptions = {
          method: 'PUT',
          headers: { 'Content-Type': 'application/json' },
          body: JSON.stringify(body)
      };
      const response = await fetch(url, requestOptions);
      return handleResponse(response);
  }
  
  // prefixed with underscored because delete is a reserved word in javascript
  async function _delete(url) {
      const requestOptions = {
          method: 'DELETE'
      };
      const response = await fetch(url, requestOptions);
      return handleResponse(response);
  }
  
  // helper functions
  
  function handleResponse(response) {
      return response.text().then(text =&gt; {
          const data = text &amp;&amp; JSON.parse(text);
  
          if (!response.ok) {
              const error = (data &amp;&amp; data.message) || response.statusText;
              return Promise.reject(error);
          }
  
          return data;
      });
  }</code></pre>
  </div>
  </div>
  </p>