Spaces:
Running
Running
import structlog | |
from fastapi import HTTPException | |
app_logger = structlog.stdlib.get_logger(__name__) | |
def divide(a: int, b: int) -> float: | |
app_logger.info(f"a:{a}, b:{b}.") | |
result = a / b | |
app_logger.info(f"result:{result}.") | |
return result | |
# @session_logger.set_uuid_logging | |
def request_formatter(text: str) -> dict: | |
app_logger.info("start request...") | |
try: | |
app_logger.info(f"input text we need to treat as an integer: {text}.") | |
b = int(text) | |
transformed_text = f"input after integer cast: {b}." | |
try: | |
result_division = divide(100, b) | |
app_logger.info(f"some_function, result_division:{result_division}.") | |
return {"text": transformed_text, "result": result_division} | |
except ZeroDivisionError as zde: | |
app_logger.info(f"exception:{zde}.") | |
raise HTTPException(status_code=500, detail="Internal server error") | |
except ValueError as ve: | |
app_logger.info(f"exception:{ve}.") | |
raise HTTPException(status_code=500, detail="Internal server error") | |