title: react-admin: ERROR: The dataProvider threw an error. It should return a rejected Promise instead - easy fix?
body: <p>In an react-admin 3.2.3 edit form I need to show related records (the list of job records) from a different resource. The relation is a bit weird and requires string parsing so I can't just use the built-in <code>ReferenceField</code>. That's why I am trying to call the dataProvider's <code>getList</code> function using the <code>useGetList</code> hook. Unfortunately I get an error on form rendering:</p>
  
  <blockquote>
    <p>The dataProvider threw an error. It should return a rejected Promise
    instead</p>
  </blockquote>
  
  <p>This is the getList function of my custom dataprovider:</p>
  
  <pre><code> getList: (resource, params) =&gt; {
          console.log('DataProvider.GetList ');
          console.log(resource);
          console.log(params);
          const { page, perPage } = params.pagination;
          const { field, order } = params.sort;
          const query = {
              ...fetchUtils.flattenObject(params.filter),
              _sort: field,
              _order: order,
              _start: (page - 1) * perPage,
              _end: page * perPage,
          };
          const url = `${getUrl(resource)}?${stringify(query)}`;
          const paging = supportsPaging(resource);
  
          return httpClient(url).then(
              ({ headers, json }) =&gt; {
                  var result = [];
  
                  // Implementierung von clientseitigem Paging &amp; Filtering
                  var filtered = applyFilter(json, params.filter);
                  if (!paging) {
                      filtered=applyPagination(filtered, page, perPage);
                  }
                  else {
                      result = filtered;
                  }
  
                  return {
                      data: result,
                      total: json.length 
                  };
              }, ({ reason }) =&gt; {
  
                  console.log(reason);
              }).catch((e)=&gt;{
                  console.log(e);
              });
      }
  </code></pre>
  
  <p>I use this custom component in the edit form. </p>
  
  <pre><code>export const CSEJobList = ({ ...props }) =&gt; {
      const form = useForm();
      var formdata = form.getState().values;
      console.log("CSEJobList");
      if (formdata &amp;&amp; formdata.status &amp;&amp; formdata.status.id &gt;= 2) {
          var data = GetJobData({ 'filter': { type: 'abeitsschein_id_' + formdata.id } });
          return data;
      }
      else {
          return &lt;div&gt;Test&lt;/div&gt;
      }
  };
  CSEJobList.defaultProps = { label: 'Arbeitsschein', addLabel: true };
  
    const GetJobData = (params) =&gt; {
          let parms = { "pagination": { "page": 0, "perPage": 25 }, "sort": { "field": "id", "order": "ASC" }, "filter": {} };
          const { data, loading, error } = useGetList('jobs', parms);
          if (loading) { return &lt;LinearProgress /&gt;; }
          if (error) { return &lt;p&gt;ERROR&lt;/p&gt;; }
          return &lt;p&gt;{data}&lt;/p&gt;;
      };
  </code></pre>
  
  <p>This is just a basic test. Proper display of result data is not implemented yet since the call results in the mentioned error.</p>
  
  <p>I read the documentation (<a href="https://marmelab.com/react-admin/Actions.html#specialized-hooks" rel="noreferrer">https://marmelab.com/react-admin/Actions.html#specialized-hooks</a>) about querying the API, fiddled around a lot, but I fail because of my limited understanding of promises.</p>
  
  <p>Is there an easy fix?</p>
  
  <p><strong>Update:</strong></p>
  
  <p>I changed the dataProvider <code>getList</code> function like so, return rejected promises as suggested:</p>
  
  <pre><code>getList: (resource, params) =&gt; {
      console.log('DataProvider.GetList ');
      console.log(resource);
      console.log(params);
      const { page, perPage } = params.pagination;
      const { field, order } = params.sort;
      const query = {
          ...fetchUtils.flattenObject(params.filter),
          _sort: field,
          _order: order,
          _start: (page - 1) * perPage,
          _end: page * perPage,
      };
      const url = `${getUrl(resource)}?${stringify(query)}`;
      const paging = supportsPaging(resource);
  
      return httpClient(url).then(
          ({ headers, json }) =&gt; {
              var result = [];
  
              // Implementierung von clientseitigem Paging &amp; Filtering
              var filtered = applyFilter(json, params.filter);
              if (!paging) {
                  filtered=applyPagination(filtered, page, perPage);
              }
              else {
                  result = filtered;
              }
  
              return {
                  data: result,
                  total: json.length,  // Erfordert nun keinen speziellen Header mehr, CSE-Connect kompatibel
              };
          }, ({ reason }) =&gt; {
              return Promise.reject(reason);
          }).catch((e)=&gt;{
              console.log(e);
              return Promise.reject(e);
          });
  },
  </code></pre>
  
  <p>It had no effect. After some debugging I realized that in the  <code>GetJobData</code> function the line</p>
  
  <pre><code>if (loading) { return &lt;LinearProgress /&gt;; }
  </code></pre>
  
  <p>causes the error. Exactly the same works in other parts of the code, so the suspect is not <code>LinearProgress</code>. I actually have no Idea what causes the error. Debugging is hard to impossible because of timeouts.</p>
  
  <p>This is the full stack trace:</p>
  
  <pre><code>useDataProvider.js:334 Uncaught Error: The dataProvider threw an error. It should return a rejected Promise instead.
      at performQuery (useDataProvider.js:334)
      at Proxy.&lt;anonymous&gt; (useDataProvider.js:163)
      at JSON.stringify.query (useQueryWithStore.js:116)
      at commitHookEffectList (react-dom.development.js:22030)
      at commitPassiveHookEffects (react-dom.development.js:22064)
      at HTMLUnknownElement.callCallback (react-dom.development.js:336)
      at Object.invokeGuardedCallbackDev (react-dom.development.js:385)
      at invokeGuardedCallback (react-dom.development.js:440)
      at flushPassiveEffectsImpl (react-dom.development.js:25392)
      at unstable_runWithPriority (scheduler.development.js:697)
      at runWithPriority$2 (react-dom.development.js:12149)
      at flushPassiveEffects (react-dom.development.js:25361)
      at performSyncWorkOnRoot (react-dom.development.js:24251)
      at react-dom.development.js:12199
      at unstable_runWithPriority (scheduler.development.js:697)
      at runWithPriority$2 (react-dom.development.js:12149)
      at flushSyncCallbackQueueImpl (react-dom.development.js:12194)
      at flushSyncCallbackQueue (react-dom.development.js:12182)
      at batchedUpdates$1 (react-dom.development.js:24392)
      at Object.notify (Subscription.js:19)
      at Subscription.notifyNestedSubs (Subscription.js:92)
      at Subscription.handleChangeWrapper (Subscription.js:97)
      at dispatch (redux.js:222)
      at middleware.js:22
      at redux-saga-core.esm.js:1410
      at useDataProvider.js:300
  </code></pre>