feat(V2): error envelope module estratto da server.py

This commit is contained in:
AdrianoDev
2026-04-30 18:17:15 +02:00
parent 993326136b
commit 80a4a88cb1
2 changed files with 80 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
from __future__ import annotations
from cerbero_mcp.common.errors import error_envelope, HTTP_CODE_MAP
def test_envelope_minimal():
e = error_envelope(type_="x", code="C", message="m", retryable=False)
assert e["error"]["code"] == "C"
assert e["error"]["retryable"] is False
assert "request_id" in e
assert "data_timestamp" in e
def test_envelope_with_suggested_fix_and_details():
e = error_envelope(
type_="validation_error",
code="INVALID_INPUT",
message="bad",
retryable=False,
suggested_fix="check field x",
details={"field": "x"},
)
assert e["error"]["suggested_fix"] == "check field x"
assert e["error"]["details"] == {"field": "x"}
def test_http_code_map_has_common_codes():
assert HTTP_CODE_MAP[401] == "UNAUTHORIZED"
assert HTTP_CODE_MAP[502] == "UPSTREAM_ERROR"