err_handling.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:triggear 作者: futuresimple 项目源码 文件源码
def handle_exceptions():
    def wrapper(func):
        @functools.wraps(func)
        async def wrapped(*args: Tuple[Any]) -> Response:
            try:
                return await func(*args)
            except KeyError as missing_key:
                logging.warning(f"Error in {func}: {missing_key} key is missing")
                return aiohttp.web.Response(text=f'Error: {missing_key} is missing in request', status=400)
            except TriggearTimeoutError as timeout_error:
                logging.exception(f'Timeout error raised')
                return aiohttp.web.Response(text=str(timeout_error), reason=f'Timeout when accessing resources: {str(timeout_error)}', status=504)
            except GithubException as github_exception:
                logging.exception(f'Github client raised exception')
                return aiohttp.web.Response(reason=str(github_exception.data), status=github_exception.status)
        return wrapped
    return wrapper
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号