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

Unable to get server error message on catch #97

Closed
lightmyfire17 opened this issue Apr 29, 2020 · 3 comments
Closed

Unable to get server error message on catch #97

lightmyfire17 opened this issue Apr 29, 2020 · 3 comments

Comments

@lightmyfire17
Copy link

lightmyfire17 commented Apr 29, 2020

Version

v0.5.0

Reproduction link

https://jsfiddle.net/eobk1pam/1/

Steps to reproduce

Use any HTTP Methods via $http ($get, delete, $put, etc.), try to catch the error like:
this.$http .$get("http://nuxthttperrors.io/error") .then(resp => console.log(resp)) .catch(e => console.log(e.response.data));

What is expected ?

Expected to get the error response message, like in network tab in chrome.

P.S. Working like a charm in axios.

What is actually happening?

The error response object is always empty:
{ name: "HTTPError", response: {} }

@ghost ghost added the cmty:bug-report label Apr 29, 2020
@dekadentno
Copy link

Try to write the catch block like this:
.catch(async err => { let error = await err.response.json(); console.log('error: ', error); })

@atinux
Copy link
Member

atinux commented Jul 14, 2020

Hi @dekadentno

This has been fixed in #113 and available in https://github.com/nuxt/http/releases/tag/v0.5.4

Keep in mind that err.response can be undefined if the request cannot hit the server.

@lightmyfire17
Copy link
Author

Great, thanks.

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

No branches or pull requests

3 participants