Merge pull request #222 from fronzbot/no-camera-enabled-bug
Log response code and message if not trying to re-authorize
This commit is contained in:
@@ -11,3 +11,5 @@ AUTH_TOKEN = (
|
||||
"Authentication header incorrect. Are you sure you received your token?"
|
||||
)
|
||||
REQUEST = (4, "Cannot perform request (get/post type incorrect)")
|
||||
|
||||
BLINK_ERRORS = [101, 400, 404]
|
||||
|
||||
@@ -86,16 +86,21 @@ def http_req(blink, url='http://example.com', data=None, headers=None,
|
||||
try:
|
||||
response = blink.session.send(prepped, stream=stream)
|
||||
if json_resp and 'code' in response.json():
|
||||
if is_retry:
|
||||
resp_dict = response.json()
|
||||
code = resp_dict['code']
|
||||
message = resp_dict['message']
|
||||
if is_retry and code in ERROR.BLINK_ERRORS:
|
||||
_LOGGER.error("Cannot obtain new token for server auth.")
|
||||
return None
|
||||
else:
|
||||
elif code in ERROR.BLINK_ERRORS:
|
||||
headers = attempt_reauthorization(blink)
|
||||
if not headers:
|
||||
raise exceptions.ConnectionError
|
||||
return http_req(blink, url=url, data=data, headers=headers,
|
||||
reqtype=reqtype, stream=stream,
|
||||
json_resp=json_resp, is_retry=True)
|
||||
_LOGGER.warning("Response from server: %s - %s", code, message)
|
||||
|
||||
except (exceptions.ConnectionError, exceptions.Timeout):
|
||||
_LOGGER.info("Cannot connect to server with url %s.", url)
|
||||
if not is_retry:
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
codecov:
|
||||
branch: dev
|
||||
coverage:
|
||||
status:
|
||||
project:
|
||||
default:
|
||||
threshold: 0.02
|
||||
|
||||
comment: true
|
||||
require_ci_to_pass: yes
|
||||
range: 65..90
|
||||
round: down
|
||||
precision: 1
|
||||
@@ -123,8 +123,8 @@ class TestBlinkSetup(unittest.TestCase):
|
||||
def test_bad_request(self, mock_sess):
|
||||
"""Check that we raise an Exception with a bad request."""
|
||||
self.blink.session = create_session()
|
||||
explog = ("ERROR:blinkpy.helpers.util:"
|
||||
"Cannot obtain new token for server auth.")
|
||||
explog = ("WARNING:blinkpy.helpers.util:"
|
||||
"Response from server: 200 - foo")
|
||||
with self.assertRaises(BlinkException):
|
||||
http_req(self.blink, reqtype='bad')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user