[Vuejs]-Send error message from flask API to vue.js frontend if eval function giving error to apply calculation in database table

3👍

As others have stated, you can use a try/except to catch the error. Then, if the error is caught, you can return an object with the error instead of the data in this case.

It’s usually best practice for API calls to return both a success/fail boolean and the data itself. So, in this example, you could return the following (represented as JSON)…

On success:

{
   success: true,
   data: ...
}

When the error is caught:

{
   success: false,
   data: "The error message"
}

You can use a JavaScript’s built in alert() function to display an alert, or you can use something like vue-simple-alert.

Leave a comment