def catch_errors(func):
"""Decorator which catches all errors and tries to print them."""
@six.wraps(func)
@click.pass_context
def decorator(ctx, *args, **kwargs):
try:
return func(*args, **kwargs)
except exceptions.DecapodAPIError as exc:
utils.format_output_json(ctx, exc.json, True)
except exceptions.DecapodError as exc:
click.echo(six.text_type(exc), err=True)
finally:
ctx.close()
ctx.exit(os.EX_SOFTWARE)
return decorator
评论列表
文章目录