fix: unify error response format with error_code, message and domain fields

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Misaka_Company
2026-05-11 12:38:37 +08:00
parent 6a4ea34e24
commit e9bb9d6be0
5 changed files with 72 additions and 27 deletions

View File

@@ -14,7 +14,7 @@ def test_register_location_success(client: TestClient):
def test_register_location_duplicate(client: TestClient):
"""重复上架 — 应返回 409"""
"""重复上架 — 应返回 409,包含统一错误格式"""
client.post(
"/CargoTrace/location",
json={"zongpai_no": "26C999", "location_code": "A01-02-03"},
@@ -25,26 +25,29 @@ def test_register_location_duplicate(client: TestClient):
)
assert resp.status_code == 409
data = resp.json()
assert data["detail"]["error_code"] == "DUPLICATE_LOCATION"
assert "existing_location" in data["detail"]["detail"]
assert data["error_code"] == "DUPLICATE_LOCATION"
assert data["location_code"] == "A01-02-03"
assert "registered_at" in data
def test_register_location_invalid_zongpai(client: TestClient):
"""无效总排号 — 应返回 422"""
"""无效总排号 — 应返回 400"""
resp = client.post(
"/CargoTrace/location",
json={"zongpai_no": "INVALID", "location_code": "A01-02-03"},
)
assert resp.status_code == 422
assert resp.status_code == 400
assert resp.json()["error_code"] == "INVALID_ZONGPAI"
def test_register_location_invalid_location(client: TestClient):
"""无效货位号 — 应返回 422"""
"""无效货位号 — 应返回 400"""
resp = client.post(
"/CargoTrace/location",
json={"zongpai_no": "26T999", "location_code": "bad-location"},
)
assert resp.status_code == 422
assert resp.status_code == 400
assert resp.json()["error_code"] == "INVALID_LOCATION"
def test_register_location_trans_location(client: TestClient):