question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issues dealing with Error Response as per documentation

See original GitHub issue

What you were expecting: I expected react-admin to gracefully deal with an error response from dataProvider having status 404

What happened instead: A lot of errors are shown in the console, indicating that an error occurred.

Steps to reproduce: 1- Create a custom dataProvider using @urql/core and set it up for the <Admin> component. 2- On getOne, when the GraphQL response returns {"data":{"result":null}}, throw an HttpError (from react-admin) with status set to 404 3- Navigate to any existing item on the list, and then change the url to a non-existent item id 4- Watch the network and console in browser’s developer tools

Related code:

Partial implementation of getOne for the specific resource:

  const response = await query.toPromise();   // query not relevant for this sample

  if (response.error) {
    throw response.error;      // CombinedError from URQL
  }

  if (!response.data?.result) {
    const error = new HttpError('No data returned', 404, response);   // from react-admin
    console.dir(error);
    throw error;
  }

  return {
    data: response.data.result!,
  };

Network POST is correct:

image

and receives expected response:

{"data":{"result":null}}

Other information:

When the API backend returns an error, the Data Provider should return a rejected Promise containing an Error object. This object should contain a status property with the HTTP response code (404, 500, etc.). React-admin inspects this error code, and uses it for authentication (in case of 401 or 403 errors). Besides, react-admin displays the error message on screen in a temporary notification.

and also:

If you use another HTTP client, make sure you return a rejected Promise. You can use the HttpError class to throw an error with status in one line

Environment

  • React-admin version: ^4.0.3
  • Last version that did not exhibit the issue (if applicable): NA
  • React version: ^18.1.0
  • Browser: Firefox 100.0.2
  • Stack trace (in case of a JS error): image This stack trace is printed 99+ times in the console, in rapid successions, almost blocking the browser’s UI. I can see the HttpError is thrown at apiConventions.ts file (where the snippet above is taken from), and it is called by a Retryer. I do not see in the Retryer any code dealing with status property from the error.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
fzaninottocommented, Jul 21, 2022

No news for some time, so I’ll close this issue. I you can provide a repro, we’ll reopen it.

0reactions
iskandersierracommented, Jun 13, 2022

I have not abandoned this issue, just looking for some time to prepare the simplest repro.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Best practices for API error handling and troubleshooting
Best practices for Orange API error handling and troubleshooting. ... This document provides details about error cases to be managed by your ...
Read more >
Web API Error Handling: How To Make Debugging Easier
Tip 1: Stick with well-known codes ; 500, Internal Server Error, When something goes wrong on the server, the consumer can't do anything...
Read more >
Error Handling and Troubleshooting with API - YouTube
An important element of any software application is concise, useful error handling. Error handling refers to the anticipation, detection, ...
Read more >
API Documentation - Error handling - Rev
Error Handling ; The user/client API keys were not specified, or were not valid, 401, Empty ; Requested operation is not valid (eg...
Read more >
Expose API error handling not resulting in expected response
When an unhandled exception occurs in an exposed REST services method, the Platform produces a default REST error output, with an "Errors" attribute...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found