I am using rails on the backend and vue.js on the front end. I am trying to print the error in case there is any. Under the .catch
I have got the error as below but cannot fetch the message from it. Kindly help me resolve it.
.catch(function (error) {
debugger
});
In the console, if I try error.response.data.error
this returns '{:message=>"Amount is less than the minimum value"}'
I am not able to figure out how I can fetch just the message.
Error Answer
CodePudding user response:
Your baclend is not serializing object correctly. So message is a part of a string instead of JSON property. If you don't want to change that you can use
const message = error.response.data.error.substring(
str.indexOf('"') 1,
str.lastIndexOf('"')
);