Issues dealing with Error Response as per documentation
See original GitHub issueWhat 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:
and receives expected response:
{"data":{"result":null}}
Other information:
- Documentation on Error Format states that:
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):
This stack trace is printed
99+
times in the console, in rapid successions, almost blocking the browser’s UI. I can see theHttpError
is thrown atapiConventions.ts
file (where the snippet above is taken from), and it is called by aRetryer
. I do not see in theRetryer
any code dealing withstatus
property from the error.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
No news for some time, so I’ll close this issue. I you can provide a repro, we’ll reopen it.
I have not abandoned this issue, just looking for some time to prepare the simplest repro.