mirror of
https://github.com/jaypyles/Scraperr.git
synced 2025-11-26 11:03:25 +00:00
* chore: refactor wip * chore: refactor wip * chore: refactor wip * chore: refactor wip * chore: refactor wip * chore: refactor wip * chore: work in progress * chore: work in progress * chore: work in progress * chore: work in progress * chore: work in progress * chore: work in progress * chore: work in progress * chore: work in progress * chore: work in progress * chore: refactor wip * chore: work in progress * chore: refactor wip * chore: refactor wip * chore: refactor wip * fix: build * fix: cypress test * fix: cypress test * fix: cypress test * fix: cypress test * fix: cypress test * fix: cypress test * fix: cypress test * fix: cypress test * fix: cypress tests * fix: cypress tests * fix: cypress tests * fix: cypress tests * fix: cypress tests * fix: cypress tests * fix: cypress tests * fix: cypress tests * fix: cypress tests * fix: cypress tests * fix: cypress tests * fix: cypress tests * fix: cypress tests * fix: cypress tests * fix: cypress tests * fix: cypress tests * fix: cypress tests
32 lines
879 B
Python
32 lines
879 B
Python
# STL
|
|
import logging
|
|
import traceback
|
|
from typing import Any, Union, Callable, Awaitable
|
|
from functools import wraps
|
|
|
|
# PDM
|
|
from fastapi.responses import JSONResponse
|
|
|
|
|
|
def handle_exceptions(
|
|
logger: logging.Logger,
|
|
) -> Callable[
|
|
[Callable[..., Awaitable[Any]]], Callable[..., Awaitable[Union[Any, JSONResponse]]]
|
|
]:
|
|
def decorator(
|
|
func: Callable[..., Awaitable[Any]],
|
|
) -> Callable[..., Awaitable[Union[Any, JSONResponse]]]:
|
|
@wraps(func)
|
|
async def wrapper(*args: Any, **kwargs: Any) -> Union[Any, JSONResponse]:
|
|
try:
|
|
return await func(*args, **kwargs)
|
|
|
|
except Exception as e:
|
|
logger.error(f"Exception occurred: {e}")
|
|
traceback.print_exc()
|
|
return JSONResponse(content={"error": str(e)}, status_code=500)
|
|
|
|
return wrapper
|
|
|
|
return decorator
|