数据目录 F2b:剖析的 409、剖析设置的 422 带机读码,界面不再从原话里认是哪一种——服务端用 api/coded.CodedHTTPException:剖析开始不了的五种情况带 code(profile_disabled、datasource_inactive、schema_missing、profile_busy、snapshot_tampered),保存数据源时剖析设置不合规带 code=profile_settings_invalid 和出错的那一项 field(max_queries……),给人看的那句不变;CodedHTTPException 多一个可选的 field;前端 profileBlockOf、profileFieldOfRejection 只认 code 和 field,没带机读码的旧响应按通用提示处理;补后端测试和检查脚本的断言(伪造的 409、422 都带 code)

This commit is contained in:
ThearchyHelios
2026-10-04 03:03:23 +08:00
parent bc615670ef
commit 5b3839f787
11 changed files with 172 additions and 60 deletions
+17 -6
View File
@@ -11,17 +11,28 @@ from fastapi.responses import JSONResponse
#: 限定的数据源一个都不在了(删了或停用了),见 copilot._sources
DATASOURCE_SCOPE_EMPTY = "datasource_scope_empty"
#: 保存数据源时剖析设置不合规(422):field 是出错的那一项(max_queries……),说不清是哪一项时没有 field
PROFILE_SETTINGS_INVALID = "profile_settings_invalid"
#: 剖析开始不了(409)的五种情况,见 api/catalog.profile_catalog_tables
PROFILE_DISABLED = "profile_disabled"
DATASOURCE_INACTIVE = "datasource_inactive"
SCHEMA_MISSING = "schema_missing"
PROFILE_BUSY = "profile_busy"
SNAPSHOT_TAMPERED = "snapshot_tampered"
class CodedHTTPException(HTTPException):
def __init__(self, status_code: int, detail: str, code: str) -> None:
"""field:出错的是哪一项(表单据此把报错落到那一格)。可选,没有就不出现在返回里。"""
def __init__(self, status_code: int, detail: str, code: str, *, field: str | None = None) -> None:
super().__init__(status_code, detail)
self.code = code
self.field = field
async def coded_handler(_: Request, exc: Exception) -> JSONResponse:
assert isinstance(exc, CodedHTTPException)
return JSONResponse(
status_code=exc.status_code,
content={"detail": exc.detail, "code": exc.code},
headers=exc.headers,
)
content: dict[str, str] = {"detail": exc.detail, "code": exc.code}
if exc.field:
content["field"] = exc.field
return JSONResponse(status_code=exc.status_code, content=content, headers=exc.headers)