This commit is contained in:
2026-06-22 08:55:57 +08:00
parent dbb87823e8
commit 6ade6e8fa9
325 changed files with 41131 additions and 855 deletions
+24 -10
View File
@@ -18,20 +18,22 @@ type Code string
// Canonical error codes. Keep this list in sync with HTTPStatus and any
// downstream consumers (e.g., HTTP transport, OpenAPI schemas).
const (
CodeInvalidInput Code = "invalid_input"
CodeUnauthorized Code = "unauthorized"
CodeForbidden Code = "forbidden"
CodeNotFound Code = "not_found"
CodeConflict Code = "conflict"
CodeRateLimited Code = "rate_limited"
CodeUpstream Code = "upstream_error"
CodeUnavailable Code = "unavailable"
CodeInternal Code = "internal"
CodeInvalidInput Code = "invalid_input"
CodeUnauthorized Code = "unauthorized"
CodeForbidden Code = "forbidden"
CodeNotFound Code = "not_found"
CodeConflict Code = "conflict"
CodeFailedPrecondition Code = "failed_precondition"
CodeRateLimited Code = "rate_limited"
CodeUpstream Code = "upstream_error"
CodeUnavailable Code = "unavailable"
CodeInternal Code = "internal"
// Project 模块专用细粒度 code(HTTP 仍 409,但前端可据此区分提示)。
CodeProjectSlugTaken Code = "project_slug_taken"
CodeProjectArchived Code = "project_archived"
CodeRequirementClosed Code = "requirement_closed"
CodePhaseGateFailed Code = "phase_gate_failed"
// Workspace 模块细粒度 code
CodeWorkspaceSlugTaken Code = "workspace_slug_taken"
@@ -108,6 +110,10 @@ const (
CodeRunProfileDisabled Code = "run.profile_disabled"
CodeRunSpawnFailed Code = "run.spawn_failed"
CodeRunCommandInvalid Code = "run.command_invalid"
// 一次性 exec(run_command / run_tests)专用错误。
CodeRunExecTimeout Code = "run.exec_timeout"
CodeRunExecCommandNotAllowed Code = "run.exec_command_not_allowed"
CodeRunExecFailed Code = "run.exec_failed"
)
// AppError is the application's structured error type. It carries a stable
@@ -179,10 +185,12 @@ func HTTPStatus(code Code) int {
case CodeNotFound:
return http.StatusNotFound
case CodeConflict,
CodeProjectSlugTaken, CodeProjectArchived, CodeRequirementClosed,
CodeProjectSlugTaken, CodeProjectArchived, CodeRequirementClosed, CodePhaseGateFailed,
CodeWorkspaceSlugTaken, CodeWorkspaceSyncInProgress,
CodeWorktreeBranchConflict, CodeWorktreeAlreadyActive:
return http.StatusConflict
case CodeFailedPrecondition:
return http.StatusPreconditionFailed
case CodeRateLimited:
return http.StatusTooManyRequests
case CodeUpstream:
@@ -257,6 +265,12 @@ func HTTPStatus(code Code) int {
return http.StatusBadRequest
case CodeRunSpawnFailed:
return http.StatusBadGateway
case CodeRunExecTimeout:
return http.StatusGatewayTimeout
case CodeRunExecCommandNotAllowed:
return http.StatusForbidden
case CodeRunExecFailed:
return http.StatusInternalServerError
default:
return http.StatusInternalServerError
}
+1
View File
@@ -37,6 +37,7 @@ func TestHTTPStatus(t *testing.T) {
CodeProjectSlugTaken: http.StatusConflict,
CodeProjectArchived: http.StatusConflict,
CodeRequirementClosed: http.StatusConflict,
CodePhaseGateFailed: http.StatusConflict,
CodeRateLimited: http.StatusTooManyRequests,
CodeUpstream: http.StatusBadGateway,
CodeUnavailable: http.StatusServiceUnavailable,