Brushed up the backend, added writing task 1 academic prompt gen and grading ENCOA-274
This commit is contained in:
15
ielts_be/utils/handle_exception.py
Normal file
15
ielts_be/utils/handle_exception.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import functools
|
||||
from typing import Callable, Any
|
||||
from fastapi import Response
|
||||
|
||||
|
||||
def handle_exception(status_code: int = 500):
|
||||
def decorator(func: Callable) -> Callable:
|
||||
@functools.wraps(func)
|
||||
async def wrapper(*args: Any, **kwargs: Any) -> Any:
|
||||
try:
|
||||
return await func(*args, **kwargs)
|
||||
except Exception as e:
|
||||
return Response(content=str(e), status_code=status_code)
|
||||
return wrapper
|
||||
return decorator
|
||||
Reference in New Issue
Block a user