feat(chat): migration 0004 + errs codes for chat/llm/storage

This commit is contained in:
2026-05-04 00:15:13 +08:00
parent a79eb82ab5
commit eb73fbba46
4 changed files with 189 additions and 0 deletions
+40
View File
@@ -44,6 +44,28 @@ const (
CodeWorktreePathInvalid Code = "worktree_path_invalid"
CodeGitCredentialInvalid Code = "git_credential_invalid"
CodeGitCmdFailed Code = "git_cmd_failed"
// Chat 模块
CodeChatConversationNotFound Code = "chat.conversation_not_found"
CodeChatMessageNotFound Code = "chat.message_not_found"
CodeChatMessageNotPending Code = "chat.message_not_pending"
CodeChatConcurrentMessage Code = "chat.concurrent_message"
CodeChatAttachmentTooLarge Code = "chat.attachment_too_large"
CodeChatAttachmentUnsupportedMime Code = "chat.attachment_unsupported_mime"
CodeChatModelCapabilityMismatch Code = "chat.model_capability_mismatch"
CodeChatTemplateNotFound Code = "chat.template_not_found"
CodeChatEndpointNotFound Code = "chat.endpoint_not_found"
CodeChatModelNotFound Code = "chat.model_not_found"
// LLM 域
CodeLLMUpstream Code = "llm.upstream_error"
CodeLLMTimeout Code = "llm.timeout"
CodeLLMRateLimited Code = "llm.rate_limited"
CodeLLMContextTooLong Code = "llm.context_too_long"
// Storage 域
CodeStoragePutFailed Code = "storage.put_failed"
CodeStorageGetFailed Code = "storage.get_failed"
)
// AppError is the application's structured error type. It carries a stable
@@ -131,6 +153,24 @@ func HTTPStatus(code Code) int {
return http.StatusBadRequest
case CodeWorktreeNotHeldByCaller:
return http.StatusForbidden
case CodeChatConversationNotFound, CodeChatMessageNotFound,
CodeChatTemplateNotFound, CodeChatEndpointNotFound, CodeChatModelNotFound:
return http.StatusNotFound
case CodeChatMessageNotPending, CodeChatConcurrentMessage,
CodeChatModelCapabilityMismatch:
return http.StatusConflict
case CodeChatAttachmentTooLarge:
return http.StatusRequestEntityTooLarge
case CodeChatAttachmentUnsupportedMime:
return http.StatusUnsupportedMediaType
case CodeLLMRateLimited:
return http.StatusTooManyRequests
case CodeLLMTimeout:
return http.StatusGatewayTimeout
case CodeLLMUpstream, CodeStoragePutFailed, CodeStorageGetFailed:
return http.StatusBadGateway
case CodeLLMContextTooLong:
return http.StatusBadRequest
default:
return http.StatusInternalServerError
}
+19
View File
@@ -51,6 +51,25 @@ func TestHTTPStatus(t *testing.T) {
CodeWorktreePathInvalid: http.StatusBadRequest,
CodeGitCredentialInvalid: http.StatusBadRequest,
CodeWorktreeNotHeldByCaller: http.StatusForbidden,
// Chat codes
CodeChatConversationNotFound: http.StatusNotFound,
CodeChatMessageNotFound: http.StatusNotFound,
CodeChatMessageNotPending: http.StatusConflict,
CodeChatConcurrentMessage: http.StatusConflict,
CodeChatAttachmentTooLarge: http.StatusRequestEntityTooLarge,
CodeChatAttachmentUnsupportedMime: http.StatusUnsupportedMediaType,
CodeChatModelCapabilityMismatch: http.StatusConflict,
CodeChatTemplateNotFound: http.StatusNotFound,
CodeChatEndpointNotFound: http.StatusNotFound,
CodeChatModelNotFound: http.StatusNotFound,
// LLM codes
CodeLLMUpstream: http.StatusBadGateway,
CodeLLMTimeout: http.StatusGatewayTimeout,
CodeLLMRateLimited: http.StatusTooManyRequests,
CodeLLMContextTooLong: http.StatusBadRequest,
// Storage codes
CodeStoragePutFailed: http.StatusBadGateway,
CodeStorageGetFailed: http.StatusBadGateway,
}
for code, want := range cases {
require.Equal(t, want, HTTPStatus(code), "code=%s", code)