Home > Mobile >  how to fetch data from key value pair in vuejs
how to fetch data from key value pair in vuejs

Time:10-24

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.

enter image description here

enter image description here

Error Answer

enter image description here

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('"')
);
  • Related