Skip to content

Commit

Permalink
fix: Hint for wrong credentials
Browse files Browse the repository at this point in the history
The rate limit error from the API does also occur during login if the
provided credentials are wrong. Help the user by adding a hint if this
happens during login.

Fixes #5
  • Loading branch information
nbuchwitz committed Mar 12, 2023
1 parent 3c5238e commit 49ce284
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions nc_dnsapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,18 @@ def request(self, action, **kwargs):

if data['status'] == 'success':
return data
# empty dns zone
elif data['statuscode'] == 5029:
# empty dns zone
return []
else:
raise Exception("{} ({})".format(data['longmessage'], data['statuscode']))
exception_message = f"{data['longmessage']} ({data['statuscode']})"
if data['statuscode'] == 4013 and action == "login":
exception_message += ". This error occured during login and is usually caused" \
" by wrong API credentials. Please check the provided values."

raise Exception(exception_message)
else:
raise Exception("{} ({})".format(response.reason, response.status_code))
raise Exception("f{response.reason} ({response.status_code})")

def logout(self):
self.request("logout")
Expand Down

0 comments on commit 49ce284

Please sign in to comment.