I am still quite new to React, I was trying to create some dynamic content and managing Errors with Usefetch.
getting data from 20x response codes is fine. however when response code is error (40x, 50x) I cannot get the response body.
here for example my reponse replies status 400: Bad request: content-type "application/json"
{ message: "My Custom Error Message" }
import React from "react";
import {useFetch} from "react-async";
const Feedback = () => {
const myRequest= useFecth("my_api_url");
if (myRequest.isPending)
return("Be Patient"); // works fine
if (myRequest.isFullfilled)
return(myRequest.data.myJsonObject); // works fine
if (myRequest.isRejected)
return(myRequest.error.message); // only shows 400 bad request
return(null); // request was not sent yet, don't bother
}
I can't seem to find the body in myRequest.error, and myRequest.data is empty (since myRequest.isRejected)
Is there a way to retreive response body when the http status code is error?
myRequest.IsPending=>myRequest.isPending, no? Surely the hook doesn't use a capitalIthere?errorwill not be what you want, but I'm not immediately seeing a way to tget it.