Skip to content

Commit 3f90aee

Browse files
Fix #3073 - Remote motionEye Error (#3079)
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. ``` Co-authored-by: MichaIng <micha@dietpi.com>
1 parent e1af249 commit 3f90aee

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

motioneye/remote.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,23 @@ def _make_request(
7676

7777

7878
async def _send_request(request: HTTPRequest) -> HTTPResponse:
79-
response = await AsyncHTTPClient().fetch(request, raise_error=False)
79+
try:
80+
# The raise_error=False argument only affects the HTTPError raised when a non-200 response
81+
# code is used, instead of suppressing all errors.
82+
response = await AsyncHTTPClient().fetch(request, raise_error=False)
83+
84+
if response.code != 200:
8085

81-
if response.code != 200:
82-
try:
8386
decoded = json.loads(response.body)
8487
if decoded['error'] == 'unauthorized':
8588
response.error = Exception('Authentication Error')
8689

8790
elif decoded['error']:
8891
response.error = Exception(decoded['error'])
89-
90-
except Exception as e:
91-
logging.error(f"_send_request: {e}")
92+
except Exception as e:
93+
logging.error(f"_send_request: {e}")
94+
response = HTTPResponse(request, 599)
95+
response.error = e
9296

9397
return response
9498

0 commit comments

Comments
 (0)