File size: 1,082 Bytes
c7d60e1
90dbc1a
 
c7d60e1
90dbc1a
 
 
c7d60e1
90dbc1a
c7d60e1
90dbc1a
 
 
c7d60e1
90dbc1a
c7d60e1
90dbc1a
c7d60e1
90dbc1a
 
 
 
c7d60e1
90dbc1a
 
c7d60e1
90dbc1a
 
c7d60e1
90dbc1a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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")