apisauce
apisauce copied to clipboard
Cannot read properties of undefined (reading 'status')
When the response is ERR_CONNECTION_REFUSED (in my case, server down), every API call throws an exception.
My understanding was that we shouldn't need to wrap calls inside a try/catch
block, but instead an exception is still thrown.
Is there a solution or workaround, to avoid refactoring all the code to handle api exceptions?
Version: "apisauce": "^2.1.5",
Here's the full error:
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'status') at getProblemFromError (apisauce.js:1:1) at apisauce.js:1:1 at apisauce.js:1:1 at Object.next (apisauce.js:1:1) at apisauce.js:1:1 at new Promise (
) at __awaiter (apisauce.js:1:1) at N (apisauce.js:1:1) at apisauce.js:1:1 at apisauce.js:1:1
Yeah, this is a bug. Could you help us track down where we're calling .status
on an undefined object in this case, and send in a PR?
Yeah, this is a bug. Could you help us track down where we're calling
.status
on an undefined object in this case, and send in a PR?
@jamonholmgren could the problem be here? https://github.com/infinitered/apisauce/blob/master/lib/apisauce.ts#L86
This:
if (!error.code) return getProblemFromStatus(error.response.status)
Maybe it should be like this?
if (!error.code) return getProblemFromStatus(error.response ? error.response.status : null)
We're also seeing this after upgrading from 2.1.1
to 2.1.5
. Assuming it was introduced during the removal of ramda.js
in 2.1.4
which appears to have involved a non-trivial amount of changes.
I've got a PR ready to go whenever someone has time to look at it.
:tada: This issue has been resolved in version 2.1.6 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
🎉 This issue has been resolved in version 2.1.6 🎉
The release is available on:
Your semantic-release bot 📦🚀
Hi I have upgraded to v2.1.6
but I am still experiences exceptions not being caught when the backend fails to respond to a HTTP request:
TypeError: Cannot read properties of undefined (reading 'config') at apisauce.js:1:1 at apisauce.js:1:1 at Object.next (apisauce.js:1:1) at apisauce.js:1:1 at new Promise (
) at __awaiter (apisauce.js:1:1) at N (apisauce.js:1:1) at apisauce.js:1:1 at apisauce.js:1:1 at Object.next (apisauce.js:1:1)
Is this the same issue, just happening in another part of the code?
@stesvis Interesting ... could be another part of the code. The backtrace isn't all that useful there.