Coverage for src\zapy\requests\exceptions.py: 70%

1 import functools

2 import asyncio

3

4 from zapy.base.exceptions import ZapyException, HandledException

5 from zapy.templating.traceback import copy_traceback

6

7 class RenderLocationException(ZapyException, HandledException):

8

9 namespace = "render"

10

11 def __init__(self, ex, location):

12 super().__init__(f"Error on {location}")

13 self.identifier = location

14 info = copy_traceback(self, from_exc=ex)

15 if info:

16 self.context["stacktrace"] = info

17

18

19 def error_location(location: str):

20 def decorator(function):

21 if not asyncio.iscoroutinefunction(function):

22 @functools.wraps(function)

23 def wrapper(*args, **kwargs):

24 try:

25 return function(*args, **kwargs)

26 except Exception as ex:

27 raise RenderLocationException(ex, location)

28 else:

29 @functools.wraps(function)

30 async def wrapper(*args, **kwargs):

31 try:

32 return await function(*args, **kwargs)

33 except Exception as ex:

34 raise RenderLocationException(ex, location)

35 return wrapper

36 return decorator