title: React JS React Query's useMutation: Unable to retrieve the response from the server within the onError callback
body: <p>I am working on a React JS project. I am using React query, <a href="https://react-query.tanstack.com/" rel="nofollow noreferrer">https://react-query.tanstack.com/</a> to make API requests. I am now having a problem with mutation retrieving the  response data from the server within the onError callback when the API throws 422 or 400 or 401, etc etc.</p>
  <p>This is my mutation.</p>
  <pre><code>let [ createProductMutation, { data, error } ] = useMutation((payload) =&gt; createProduct(payload), {
      onMutate: () =&gt; {
        
      },
      onSuccess: (response) =&gt; {
        
      },
      onError: (err, variables, snapshotValue) =&gt; {
        //err is not the response from the server.
      }
    })
  </code></pre>
  <p>As you can see in the onError callback, there is no way to retrieve the response from the server.</p>
  <p>The data and error (the one next to, createProductMutation) are not the response from the server too.</p>
  <p>I tried using this.</p>
  <pre><code>  try {
         let response = await createProductMutation(data);
          // response from the API is not here too, &quot;response&quot;
      } catch (e) {
          // response from the API is not here too
      }
  </code></pre>
  <p>How can I retrieve the response within the onError callback?</p>