I have an app with Rails as a backend and React as a frontend. I am trying to handle Stripe errors on server side and render any error by updating my state in the client.
here the code in my controller method:
def create
# here some code to handle payment...
rescue Stripe::CardError => e
render json: e.json_body[:error][:message], status: 422
end
and my react function that handles the response:
axios.post("/orders"})
.then(res => {
this.setState({
hasOrdered: true,
orderSuccess: true,
loading: false
});
})
.catch(err => {
console.log(err);
this.setState({
loading: false,
error: err
});
});
the console.log(err) output is simply: Error: Request failed with status code 422 whereas the response I get through the network is:
And what I want is the update the state with "Your card has insufficient funds."
How can I do this ?
