Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve catch error to return response #43

Closed
marceloavf opened this issue Nov 6, 2017 · 3 comments
Closed

Improve catch error to return response #43

marceloavf opened this issue Nov 6, 2017 · 3 comments

Comments

@marceloavf
Copy link

When using axios itself, you can use error.response to get the response of an error, e.g.:

axios.post('/formulas/create', {
	name: "",
	parts: ""
})
.then(response => { 
	console.log(response)
})
.catch(error => {
    console.log(error.response)
});

But right now it only return the scope of the error, e.g.:

[error] Error: Network Error
    at createError (D:\xampp\htdocs\xxxx\node_modules\axios\lib\core\createError.js:16:15)
    at XMLHttpRequest.handleError (D:\xampp\htdocs\xxxx\node_modules\axios\lib\adapters\xhr.js:87:14)

Is there a way to change that or I'm doing something wrong?

Thanks!

@christianmalek
Copy link
Owner

Mhm. As you can see in https://github.com/christianmalek/vuex-rest-api/blob/v2/src/Resource.ts#L70 requestFn returns an axios promise.
And https://github.com/christianmalek/vuex-rest-api/blob/v2/src/Store.ts#L183 returns the rejected promise. Do you see an error?

@marceloavf
Copy link
Author

Strange, seems to be something with axios axios/axios#960
When response code is 500/401 it doesn't return a response.

@christianmalek
Copy link
Owner

christianmalek commented Nov 6, 2017

Ah, ok. Another possibility would be that the error output is just "beautified" by Chrome/etc. So you should just try to access the error.response property. I'll close this. Feel free to reopen it.

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

No branches or pull requests

2 participants