nuxt / http

Universal HTTP Module for Nuxt.js
https://http.nuxtjs.org
MIT License
229 stars 51 forks source link

Unable to get server error message on catch #97

Closed lightmyfire17 closed 4 years ago

lightmyfire17 commented 4 years ago

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: {} }

dekadentno commented 4 years ago

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

atinux commented 4 years ago

Hi @dekadentno

This has been fixed in https://github.com/nuxt/http/pull/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 commented 4 years ago

Great, thanks.