No response data in Error Case
loiu92 opened this issue · 7 comments
Hello,
I just try your module and it's working well.
I just don't have any response object when HTTP Code is 422
body: ReadableStream { locked: false }
bodyUsed: false
config: Object { headers: {…} }
headers: Headers { }
ok: false
redirected: false
status: 422
statusText: "No Reason Phrase"
type: "cors"
url: "https://url"
<prototype>: {…}
But in Axios, i have in the returned object, a response
field then a data
with my json.
Did i do something wrong (i didn't change anything from my axios implementation)
Thanks in advance :)
It looks like at line 204-205 it checks for a 4xx/5xx status before parsing the response data, so there won't be response data on error responses.
For me, I just copied the entire index.js into my own project. Then I removed line 205 (if (!ok)...
) and changed line 219 to .then(() => ok ? response : Promise.reject(response))
. Seemed to work fine.
Hi, any plan for release of the fix?
@developit, do you plan on releasing this fix soon?
Any news on this one?
@andreychev I just published 0.4.1 with this included.
Hi @developit. I have updated redaxios. Before it, I use axios and this is my error handler example
Axios(...)
.then(..)
.catch(err=>{
if(err.response!== undefined){
// handle error data here
console.log(err.response.data)
})
But in redaxios@0.4.1 i have to refactor the code to this
Axios(...)
.then(..)
.catch(err=>{
if(err.data!== undefined){
// handle error data here
console.log(err.data)
})
Note the difference, err.response.data (axios)
vs err.data(redaxios)