1
0
mirror of https://github.com/mail-in-a-box/mailinabox.git synced 2024-12-21 07:07:05 +00:00

handle errors in management API calls properly

see #118
This commit is contained in:
Joshua Tauberer 2014-07-25 13:51:35 +00:00
parent 86ec0f6da7
commit 3a7221a69a

View File

@ -11,7 +11,12 @@ def mgmt(cmd, data=None):
try:
response = urllib.request.urlopen(req)
except urllib.error.HTTPError as e:
print(e.read().decode('utf8'))
if e.code == 401:
print("The management daemon refused access. The API key file may be out of sync. Try 'service mailinabox restart'.", file=sys.stderr)
elif hasattr(e, 'read'):
print(e.read().decode('utf8'), file=sys.stderr)
else:
print(e, file=sys.stderr)
sys.exit(1)
return response.read().decode('utf8')