vue-resource icon indicating copy to clipboard operation
vue-resource copied to clipboard

Cannot catch some errors

Open irongomme opened this issue 7 years ago • 2 comments

I'm using this kind of code :

this.$tickets.save(this.ticket).then(response => {
    //Success
    console.log(response)
}, response => {
    //Error
    console.log('Error happenned')
})

And in my case, with a 422 status error (validation error from server), i cannot execute anything in the error case .... All I have is a Chrome console log (Uncaught (in promise) Response {url: "http://api.domain.dev/v1/wifi/tickets", ok: false, status: 422, statusText: "Unprocessable Entity", headers: Headers, …})

How can I execute a custom errors handling ?

irongomme avatar Jul 27 '17 16:07 irongomme

This also occurs with 401 so i am assuming that this case applies to all 4xx errors

meldsza avatar Aug 13 '17 14:08 meldsza

Could you create a jsfiddle for your error case. The save promise should be rejected when the response status >= 300.

http/index.js

    return client(new Request(options)).then(response => {

        return response.ok ? response : Promise.reject(response);

    }, response => {

        if (response instanceof Error) {
            error(response);
        }

        return Promise.reject(response);
    });

http/response.js

        this.ok = status >= 200 && status < 300;

samsong8610 avatar Sep 25 '17 07:09 samsong8610