Skip to content

Commit

Permalink
Merge pull request #23 (error fixes)
Browse files Browse the repository at this point in the history
This improves the RobotError exception so that repr() and str() perform
more like people are used to.

Also this adds a .format() that I forgot in
bbae95a.

Thanks to @nh2 for these fixes.
  • Loading branch information
aszlig committed Jun 24, 2017
2 parents ca2d131 + e233c70 commit c597879
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
9 changes: 2 additions & 7 deletions hetzner/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
class RobotError(Exception):
def __init__(self, message, status=None):
self.message = message
formattedMessage = message if status is None else "{0} ({1})".format(message, status)
super(Exception, self).__init__(formattedMessage)
self.status = status

def __str__(self):
if self.status is None:
return self.message
else:
return "{0} ({1})".format(self.message, self.status)


class ManualReboot(Exception):
pass
Expand Down
2 changes: 1 addition & 1 deletion hetzner/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def login(self, user=None, passwd=None, force=False):
if self.user.startswith("#ws+"):
raise WebRobotError("The user {0} is a dedicated web service user "
"and cannot be used for scraping the web user "
"interface.")
"interface.".format(self.user))

# This is primarily for getting a first session cookie.
response = self.request('/login', xhr=False)
Expand Down

0 comments on commit c597879

Please sign in to comment.