mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
Add sentry_wrap decorator
This commit is contained in:
parent
0e42273e6f
commit
a4a263f142
2 changed files with 16 additions and 1 deletions
|
@ -3,7 +3,7 @@ from .sleep_until import sleep_until
|
|||
from .formatters import andformat, underscorize, ytdldateformat, numberemojiformat, ordinalformat
|
||||
from .urluuid import to_urluuid, from_urluuid
|
||||
from .multilock import MultiLock
|
||||
from .sentry import init_sentry, sentry_exc
|
||||
from .sentry import init_sentry, sentry_exc, sentry_wrap
|
||||
from .log import init_logging
|
||||
from .royaltyping import JSON
|
||||
|
||||
|
@ -20,6 +20,7 @@ __all__ = [
|
|||
"MultiLock",
|
||||
"init_sentry",
|
||||
"sentry_exc",
|
||||
"sentry_wrap",
|
||||
"init_logging",
|
||||
"JSON",
|
||||
]
|
||||
|
|
|
@ -3,6 +3,7 @@ import sys
|
|||
import traceback
|
||||
from typing import *
|
||||
from royalnet.version import semantic
|
||||
import functools
|
||||
|
||||
try:
|
||||
import sentry_sdk
|
||||
|
@ -45,3 +46,16 @@ def sentry_exc(exc: Exception,
|
|||
if __debug__:
|
||||
exc_type, exc_value, exc_traceback = sys.exc_info()
|
||||
traceback.print_exception(exc_type, exc_value, exc_traceback)
|
||||
|
||||
|
||||
def sentry_wrap(level: str = "ERROR"):
|
||||
def decorator(func: Callable):
|
||||
@functools.wraps(func)
|
||||
def new_func(*args, **kwargs):
|
||||
try:
|
||||
return func(*args, **kwargs)
|
||||
except Exception as exc:
|
||||
sentry_exc(exc=exc, level=level)
|
||||
raise
|
||||
return new_func
|
||||
return decorator
|
||||
|
|
Loading…
Reference in a new issue