vue-resource
vue-resource copied to clipboard
Cannot catch some errors
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 ?
This also occurs with 401 so i am assuming that this case applies to all 4xx errors
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;