Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

Cannot catch some errors #635

Open
irongomme opened this issue Jul 27, 2017 · 2 comments
Open

Cannot catch some errors #635

irongomme opened this issue Jul 27, 2017 · 2 comments

Comments

@irongomme
Copy link

irongomme commented Jul 27, 2017

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 ?

@meldsza
Copy link

meldsza commented Aug 13, 2017

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

@samsong8610
Copy link

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;

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants