Revision 499d9bfe snf-cyclades-app/synnefo/quotas/__init__.py
b/snf-cyclades-app/synnefo/quotas/__init__.py | ||
---|---|---|
37 | 37 |
ASTAKOS_URL) |
38 | 38 |
from astakosclient import AstakosClient |
39 | 39 |
from astakosclient.errors import AstakosClientException, QuotaLimit |
40 |
from functools import wraps |
|
40 | 41 |
|
41 | 42 |
import logging |
42 | 43 |
log = logging.getLogger(__name__) |
... | ... | |
64 | 65 |
return cls._object |
65 | 66 |
|
66 | 67 |
|
68 |
def handle_astakosclient_error(func): |
|
69 |
"""Decorator for converting astakosclient errors to 500.""" |
|
70 |
@wraps(func) |
|
71 |
def wrapper(*args, **kwargs): |
|
72 |
try: |
|
73 |
return func(*args, **kwargs) |
|
74 |
except AstakosClientException: |
|
75 |
log.exception("Unexpected error") |
|
76 |
raise faults.InternalServerError("Unexpected error") |
|
77 |
return wrapper |
|
78 |
|
|
79 |
|
|
80 |
@handle_astakosclient_error |
|
67 | 81 |
def issue_commission(user, source, provisions, |
68 | 82 |
force=False, auto_accept=False): |
69 | 83 |
"""Issue a new commission to the quotaholder. |
... | ... | |
81 | 95 |
except QuotaLimit as e: |
82 | 96 |
msg, details = render_overlimit_exception(e) |
83 | 97 |
raise faults.OverLimit(msg, details=details) |
84 |
except AstakosClientException as e: |
|
85 |
log.exception("Unexpected error") |
|
86 |
raise |
|
87 | 98 |
|
88 | 99 |
if serial: |
89 | 100 |
return QuotaHolderSerial.objects.create(serial=serial) |
... | ... | |
99 | 110 |
return resolve_commissions(reject=rejected, strict=strict) |
100 | 111 |
|
101 | 112 |
|
113 |
@handle_astakosclient_error |
|
102 | 114 |
def resolve_commissions(accept=None, reject=None, strict=True): |
103 | 115 |
if accept is None: |
104 | 116 |
accept = [] |
Also available in: Unified diff