From 047e529fe4c888196c995ebc78c9354220a50a9b Mon Sep 17 00:00:00 2001 From: "Alan D. Tse" Date: Fri, 24 Jan 2020 01:08:46 -0800 Subject: [PATCH] refactor: improve incomplete credentials message --- teslajsonpy/connection.py | 6 +++++- teslajsonpy/exceptions.py | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/teslajsonpy/connection.py b/teslajsonpy/connection.py index edb0d4d8..0cb5e569 100644 --- a/teslajsonpy/connection.py +++ b/teslajsonpy/connection.py @@ -78,9 +78,13 @@ def generate_oauth( elif refresh_token: self.oauth["grant_type"] = "refresh_token" self.oauth["refresh_token"] = refresh_token + elif not refresh_token: + raise IncompleteCredentials( + "Missing oauth authentication details: refresh token." + ) else: raise IncompleteCredentials( - "Connection requires email and password or refresh token to authenticate." + "Missing oauth authentication details: email and password." ) async def get(self, command): diff --git a/teslajsonpy/exceptions.py b/teslajsonpy/exceptions.py index df74cd73..e497b6b4 100644 --- a/teslajsonpy/exceptions.py +++ b/teslajsonpy/exceptions.py @@ -15,6 +15,9 @@ def __init__(self, code, *args, **kwargs): self.message = "" super().__init__(*args, **kwargs) self.code = code + if isinstance(code, str): + self.message = self.code + return if self.code == 401: self.message = "UNAUTHORIZED" elif self.code == 404: