Skip to content

Commit

Permalink
Catch Authentication error in one place on top
Browse files Browse the repository at this point in the history
  • Loading branch information
dmedvinsky committed May 28, 2012
1 parent bfe5c6a commit cbcf33e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
7 changes: 6 additions & 1 deletion redcliff/cli.py
Expand Up @@ -2,6 +2,7 @@

import argparse

from . import api
from .commands import dispatch, choices
from .config import get_config
from .utils import merge, error
Expand Down Expand Up @@ -41,7 +42,11 @@ def main():
error('fatal: base_url and api_key are required')
return 1

return dispatch(cmd, cmd_args, merged_conf)
try:
return dispatch(cmd, cmd_args, merged_conf)
except api.AuthError:
error('fatal: authentication error')
return 1


if __name__ == '__main__':
Expand Down
5 changes: 1 addition & 4 deletions redcliff/commands/list.py
Expand Up @@ -44,11 +44,8 @@ def run(argv, conf):

try:
data = api.issues.list(args, conf)
except api.AuthError:
error('fatal: authentication error')
return 1
except:
error('fatal: API error')
error('fatal: API error while gettings issues list')
raise
else:
renderer.issues.as_table(data)
Expand Down
11 changes: 6 additions & 5 deletions redcliff/commands/update.py
Expand Up @@ -13,7 +13,11 @@ def run(argv, conf):
args = vars(parser.parse_args(argv))

if args['status']:
status = api.statuses.by_name(args.pop('status'), conf)
try:
status = api.statuses.by_name(args.pop('status'), conf)
except:
error('fatal: API error while getting status by name')
raise
if status:
args['status_id'] = status['id']
else:
Expand All @@ -22,11 +26,8 @@ def run(argv, conf):

try:
api.issues.update(args, conf)
except api.AuthError:
error('fatal: authentication error')
return 1
except:
error('fatal: API error')
error('fatal: API error while updating')
raise
else:
success('Successfully updated.')
Expand Down

0 comments on commit cbcf33e

Please sign in to comment.