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

Cannot read properties of undefined (reading 'status') #295

Closed
stesvis opened this issue May 16, 2022 · 7 comments · Fixed by #298
Closed

Cannot read properties of undefined (reading 'status') #295

stesvis opened this issue May 16, 2022 · 7 comments · Fixed by #298

Comments

@stesvis
Copy link

stesvis commented May 16, 2022

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

@jamonholmgren
Copy link
Member

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?

@stesvis
Copy link
Author

stesvis commented May 21, 2022

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)

@markholland
Copy link

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.

@treeduship
Copy link
Contributor

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

infinitered-circleci pushed a commit that referenced this issue Aug 22, 2022
## [2.1.6](v2.1.5...v2.1.6) (2022-08-22)

### Bug Fixes

* Fixes undefined status error -- fixes [#295](#295) ([#298](#298) by [@treeduship](https://github.com/treeduship)) ([278bfbc](278bfbc))
@infinitered-circleci
Copy link

🎉 This issue has been resolved in version 2.1.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

@stesvis
Copy link
Author

stesvis commented Sep 16, 2022

🎉 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?

@jamonholmgren
Copy link
Member

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

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

Successfully merging a pull request may close this issue.

5 participants