You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
941 B
Python
46 lines
941 B
Python
from typing import Any
|
|
|
|
from fastapi import HTTPException
|
|
|
|
# Responsabilidade: padronizar erros do domínio
|
|
|
|
|
|
def build_tool_error(
|
|
*,
|
|
code: str,
|
|
message: str,
|
|
retryable: bool,
|
|
field: str | None = None,
|
|
meta: dict[str, Any] | None = None,
|
|
) -> dict[str, Any]:
|
|
payload: dict[str, Any] = {
|
|
"code": code,
|
|
"message": message,
|
|
"retryable": retryable,
|
|
"field": field,
|
|
}
|
|
if isinstance(meta, dict):
|
|
payload.update(meta)
|
|
return payload
|
|
|
|
|
|
def raise_tool_http_error(
|
|
*,
|
|
status_code: int,
|
|
code: str,
|
|
message: str,
|
|
retryable: bool,
|
|
field: str | None = None,
|
|
meta: dict[str, Any] | None = None,
|
|
) -> None:
|
|
raise HTTPException(
|
|
status_code=status_code,
|
|
detail=build_tool_error(
|
|
code=code,
|
|
message=message,
|
|
retryable=retryable,
|
|
field=field,
|
|
meta=meta,
|
|
),
|
|
)
|