I am using react-admin
framework and I am trying to get error status code (404,500), which I would be saving to some variable for later usage. For example, when I try to create an user
that has same e-mail address as already created user
, the server wont allow this operation and the request fails with status code 500
. I need that status code to save to variable and work with it later.
Does react-admin
offer this?
So far I have tried this simple code in my custom DataProvider
, but when logging it to console, it returns undefined
.
const status = params.message.status;
I wasn't able to find any other solution that I would fully understand.
Any ideas how to solve this?
Thank you in advance.
Basically this is what are you looking for:
https://developer.mozilla.org/en-US/docs/Web/API/Response/status
First of all, you actually need to request some data from the server in order to get the response.status
code. The most simple example would be this based on the link I listed before:
var myRequest = new Request(options.body); //depends on what do you want to request
fetch(myRequest).then(function (response) { //gets the response from server
console.log(response.status, 'status'); // this returns the status value
});
This should return the response.status
code.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.