-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.py
40 lines (34 loc) · 1.23 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# -*- coding: utf-8 -*-
"""
utils
:license: see LICENSE for details.
"""
import os
from sentry_sdk import capture_exception
from functools import wraps
from trytond.exceptions import (
UserError, UserWarning, ConcurrencyException, LoginException)
CONSULTANT = os.environ.get('TRYTON_CONSULTANT', '<CONSULTANT NAME>')
def patch(old_dispatch):
"""
Patch the `old_dispatcher` with an exception handler to send exceptions
which occur to sentry
:param old_dispatch: the function/method to be patched
"""
@wraps(old_dispatch)
def wrapper(*args, **kwargs):
try:
return old_dispatch(*args, **kwargs)
except (ConcurrencyException, UserError, UserWarning, LoginException):
raise
except Exception:
event_id = capture_exception()
raise UserError(
"Oops! Something terrible happened\n\n"
"Your ever loving friends at %s have been notified of "
"this grave fault!\n"
"However, if you wish to speak with an %s consultant "
"about this issue, you may use the following reference:\n\n"
"%s" % (CONSULTANT, CONSULTANT, event_id)
)
return wrapper