def _to_http_exception()

in aidial_assistant/utils/exceptions.py [0:0]


def _to_http_exception(e: Exception) -> HTTPException:
    if isinstance(e, RequestParameterValidationError):
        return HTTPException(
            message=str(e),
            status_code=422,
            type="invalid_request_error",
            param=e.param,
        )

    if isinstance(e, APIError):
        raise HTTPException(
            message=e.message,
            status_code=getattr(e, "status_code", None) or 500,
            type=e.type or "runtime_error",
            code=e.code,
            param=e.param,
        )

    return HTTPException(
        message=str(e), status_code=500, type="internal_server_error"
    )