dgreif / homebridge-hatch-baby-rest

A homebridge plugin for Hatch Baby Rest night light
MIT License
70 stars 19 forks source link

Internal Server Error #107

Closed parsap closed 1 year ago

parsap commented 1 year ago

My plugin is on a loop of 500 server errors when it tries to log in. Is this happening to anyone else? The native app still works.

body: { timestamp: '2023-06-06 21:31:03.254', status: 500, error: 'Internal Server Error', path: '/public/v1/login' },

Here is the full log.

log.txt

joshuaseltzer commented 1 year ago

Same error on my instance. Looks like the OAuth flow is failing. Guessing their API is either down or it changed...

brentleeper commented 1 year ago

Looks like the following header needs to be added to each request.

USER_AGENT: "hatch_rest_api"

brentleeper commented 1 year ago

… well actually… let me try to understand this a bit more

brentleeper commented 1 year ago

Yes, that is correct. All api requests now require the above mentioned header, including the login request.

joshuaseltzer commented 1 year ago

@brentleeper nice discovery! Hopefully the fix is just as simple as adding that header to the requests made by this plugin.

I'd do a PR myself, but I'm not at all familiar with developing these plugins or even the language used here.

brentleeper commented 1 year ago

I am on my phone currently but I just opened a PR to address this issue. It should be noted I have very little context 😅 and working off some assumptions but the maintainer should get the idea and be able to edit as needed.

brentleeper commented 1 year ago

Opened PR: https://github.com/dgreif/homebridge-hatch-baby-rest/pull/108

dgreif commented 1 year ago

The fix from #108 has been released in 4.0.1. Please let me know if this resolves your issues @parsap

eightball011854 commented 1 year ago

@dgreif major thanks for this and the ring fix last weekend - you are the best of the best of the best!

joshuaseltzer commented 1 year ago

The fix from #108 has been released in 4.0.1. Please let me know if this resolves your issues @parsap

I can personally confirm 4.0.1 is working again on my install.

Thanks again for quickly publishing this update! Couldn't live without it.

parsap commented 1 year ago

Confirmed fixed!

kenwdelong commented 1 year ago

So just to be clear - the 500s were due to a bug on our end; now fixed. The user-agent is a bit of a red herring: it could have been set to "bobs-your-uncle" and that would have avoided the bug.

The bug manifested because we are implementing some rate-limiting. Someone mentioned being in a infinite loop of 500s - there are quite a few people using this library in an infinite loop of 200s (successful logins). There are clients out there sending tens of thousands of login attempts per day. This is one of the things that prompted us to implement rate limiting!

We meant to look over the project and submit some pull requests to fix the infinite-login-loop problem, but we just haven't had the time. It would be great if someone could figure it out. The login tokens are valid for years. But be aware that as soon as we get this code spruced up the infinite login loops will be getting 429 responses, regardless of user-agent.

dgreif commented 1 year ago

Thanks for the heads up @kenwdelong, and sorry for the infinite loop login attempts! I didn't realize that was happening and haven't seen anything like that on my end, but I would gladly accept some PRs if you find the offending code.