feat: keep the gateway's words on the OCR branches too

Issue #10 Task 4: the OCR side said only 'HTTP 404'. The issue reported
the chat path, but the batch that lost its 400 was reading tables - the
same blind spot, one transport over. Reuses the shared summarizer.
This commit is contained in:
2026-08-16 06:14:07 -04:00
parent 0edb9d397a
commit a3f4cc323f
2 changed files with 52 additions and 2 deletions
+13 -1
View File
@@ -24,6 +24,11 @@ from polygateway.errors import (
SourceDeadError,
TransientError,
)
from polygateway.transports._http_errors import (
compose_message,
response_body,
summarize_body,
)
from polygateway.types import (
OcrLayoutElement,
OcrLayoutTransportResult,
@@ -74,13 +79,20 @@ def _translate_http_errors(source_name: str, operation: str) -> Iterator[None]:
def _classify_status(
exc: httpx.HTTPStatusError, source_name: str, operation: str
) -> TransientError | SourceDeadError | RequestRejectedError:
"""HTTP 状态码 → 错误四分类,**全部分支**携带响应体摘要(issue #10)。
分类映射本身零变更;摘要口径与 chat 侧共用同一实现,不得在此另起一份——
"只有一个分支用了响应体"正是 issue #10 的成因。
"""
status = exc.response.status_code
summary = summarize_body(response_body(exc.response))
ctx: dict[str, Any] = {
"source_name": source_name,
"status_code": status,
"operation": operation,
"body_text": summary,
}
message = f"{source_name} OCR {operation} HTTP {status}"
message = compose_message(f"{source_name} OCR {operation} HTTP {status}", summary)
if status >= 500 or status == 429:
return TransientError(message, **ctx)
if status in (401, 403):