Skip to content

Commit bba2149

Browse files
committed
Added exception handling in the require_api_key() decorator for AttributeError raised by the decorated function.
- Legacy-Id: 17629
1 parent b538465 commit bba2149

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

ietf/utils/decorators.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from ietf.utils.test_runner import set_coverage_checking
1818
from ietf.person.models import Person, PersonalApiKey, PersonApiKeyEvent
19+
from ietf.utils import log
1920

2021
@decorator
2122
def skip_coverage(f, *args, **kwargs):
@@ -76,7 +77,12 @@ def err(code, text):
7677
key.save()
7778
PersonApiKeyEvent.objects.create(person=person, type='apikey_login', key=key, desc="Logged in with key ID %s, endpoint %s" % (key.id, key.endpoint))
7879
# Execute decorated function
79-
return f(request, *args, **kwargs)
80+
try:
81+
ret = f(request, *args, **kwargs)
82+
except AttributeError as e:
83+
log.log("Bad API call: args: %s, kwargs: %s, exception: %s" % (args, kwargs, e))
84+
return err(400, "Bad or missing parameters")
85+
return ret
8086

8187

8288
def _memoize(func, self, *args, **kwargs):

0 commit comments

Comments
 (0)