Skip to content

Commit

Permalink
Fix #3073 - Remote motionEye Error
Browse files Browse the repository at this point in the history
If a remote motionEye is unavailable an exception was not handled.. this was due to the entirely reasonable expectation `raise_error=False` would not raise an error. This is however not the case as documented in the [tornado.httpclient](https://www.tornadoweb.org/en/stable/httpclient.html#tornado.httpclient.AsyncHTTPClient.fetch) documentation:

```
The raise_error=False argument only affects the HTTPError raised when a non-200 response code is used, instead of suppressing all errors.
```

Not entirely sure the other error 2 paths work either (i.e. `response.error` appears to expect an exception not a string).. but this commit fixes more than we started with and will fix more than it breaks 😄.
  • Loading branch information
Matthew1471 committed Nov 28, 2024
1 parent 72af371 commit 2dec5ff
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions motioneye/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,23 @@ def _make_request(


async def _send_request(request: HTTPRequest) -> HTTPResponse:
response = await AsyncHTTPClient().fetch(request, raise_error=False)
try:
# The raise_error=False argument only affects the HTTPError raised when a non-200 response
# code is used, instead of suppressing all errors.
response = await AsyncHTTPClient().fetch(request, raise_error=False)

if response.code != 200:

if response.code != 200:
try:
decoded = json.loads(response.body)

if decoded['error'] == 'unauthorized':
response.error = 'Authentication Error'

elif decoded['error']:
response.error = decoded['error']

except Exception as e:
logging.error(f"_send_request: {e}")
except Exception as e:
logging.error(f"_send_request: {e}")
response = HTTPResponse(request, 500)
response.error = e

return response

Expand Down

0 comments on commit 2dec5ff

Please sign in to comment.