[Vuejs]-Error can not show in my laravel vue js project

0πŸ‘

βœ…

I think I understand your problem now. I have had to deal with similar processing myself.

Since it looks like the error returned has the JSON format:

{
    "error": "You Already Review This Product"
}

you can add logic similar to this to your β€˜catch(error)’:

.catch(error=>{
        console.log(error);
        if (error.response) {
                if (error.response.status == 422) {
                        let errorMessage = error.response.data.error;
                        Toast.fire({
                                icon: 'error',
                                title: errorMessage,
                        });

                        this.$Progress.fail();
                }
                else {
                        console.error("Response contains error code " + error.response.status);
                }
        }
        else if (error.request) {
                console.error("No response received so logging request");
                console.error(error.request);
        }
        else {
                console.error("Problem with request: " + error.message);
        }
});

BTW, I use Axios for calling REST APIs, and I’m not sure if other ways of calling REST APIs may use a different error structure. As you probably know, you can see the error object structure in the console log.

Leave a comment