-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdecorators.py
More file actions
23 lines (22 loc) · 935 Bytes
/
decorators.py
File metadata and controls
23 lines (22 loc) · 935 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from molmass import FormulaError
def rdkit_handle_error(func):
"""Run function as normal - catch TypeError from RDKit caused by C++ error
Server will still revert to 500 status when other error occur.
"""
def wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
except (TypeError, NameError) as e:
print("RDKit unable to process mol")
import sys
print(e, file=sys.stderr, flush=True)
return {"message": "structure cant be identified"}, 400
except FormulaError as e:
print("molmass unable to process formula")
import sys
print(e, file=sys.stderr, flush=True)
return {"message": "formula cant be identified"}, 400
# Have to rename wrapper or else Flask tries to register all uses as "wrapper"
# causing AssertionError
wrapper.__name__ = func.__name__
return wrapper