apisauce icon indicating copy to clipboard operation
apisauce copied to clipboard

Cannot read properties of undefined (reading 'status')

Open stesvis opened this issue 2 years ago • 4 comments

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

stesvis avatar May 16 '22 20:05 stesvis

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 avatar May 17 '22 01:05 jamonholmgren

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)

stesvis avatar May 21 '22 00:05 stesvis

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.

markholland avatar Jun 21 '22 11:06 markholland

I've got a PR ready to go whenever someone has time to look at it.

treeduship avatar Aug 08 '22 20:08 treeduship

:tada: This issue has been resolved in version 2.1.6 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

infinitered-circleci avatar Aug 22 '22 23:08 infinitered-circleci

🎉 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 avatar Sep 16 '22 21:09 stesvis

@stesvis Interesting ... could be another part of the code. The backtrace isn't all that useful there.

jamonholmgren avatar Sep 16 '22 22:09 jamonholmgren