feat: 系统优化 - ESLint、Tailwind、前端健壮性、后端工程化、运维可观测性
- 前端: ESLint+Prettier配置、Tailwind v4配置、ErrorBoundary、全局AuthLoader优化、ReactQuery分层 - 后端: MinIO凭证移除、Docker统一为govai品牌、zerolog日志封装、错误码枚举、文件上传校验、单元测试(13项全通过) - 运维: 健康检查增强(PG/Redis ping)、Prometheus指标(/metrics端点)、多租户tenant包、RateLimit nil防御 - 移动: citation_prompt.txt → internal/assets/
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
package response
|
||||
|
||||
import "net/http"
|
||||
|
||||
// 错误码枚举,统一业务错误定义
|
||||
type ErrCode int
|
||||
|
||||
const (
|
||||
// 通用错误 (0xxxx)
|
||||
ErrCodeSuccess ErrCode = 0
|
||||
ErrCodeBadRequest ErrCode = 40001
|
||||
ErrCodeUnauthorized ErrCode = 40101
|
||||
ErrCodeForbidden ErrCode = 40301
|
||||
ErrCodeNotFound ErrCode = 40401
|
||||
ErrCodeRequestTimeout ErrCode = 40801
|
||||
ErrCodeTooManyRequests ErrCode = 42901
|
||||
ErrCodeInternalError ErrCode = 50001
|
||||
ErrCodeServiceUnavailable ErrCode = 50301
|
||||
ErrCodeGatewayTimeout ErrCode = 50401
|
||||
|
||||
// 业务错误 (6xxxx)
|
||||
ErrCodeInvalidToken ErrCode = 40102
|
||||
ErrCodeTokenExpired ErrCode = 40103
|
||||
ErrCodeUserDisabled ErrCode = 40104
|
||||
ErrCodeOrgNotFound ErrCode = 40402
|
||||
ErrCodeAppNotFound ErrCode = 40403
|
||||
ErrCodeKnowledgeNotFound ErrCode = 40404
|
||||
ErrCodeInsufficientQuota ErrCode = 42902
|
||||
ErrCodeFileTooLarge ErrCode = 40002
|
||||
ErrCodeInvalidFileType ErrCode = 40003
|
||||
)
|
||||
|
||||
var httpStatusMap = map[ErrCode]int{
|
||||
ErrCodeSuccess: http.StatusOK,
|
||||
ErrCodeBadRequest: http.StatusBadRequest,
|
||||
ErrCodeUnauthorized: http.StatusUnauthorized,
|
||||
ErrCodeForbidden: http.StatusForbidden,
|
||||
ErrCodeNotFound: http.StatusNotFound,
|
||||
ErrCodeRequestTimeout: http.StatusRequestTimeout,
|
||||
ErrCodeTooManyRequests: http.StatusTooManyRequests,
|
||||
ErrCodeInternalError: http.StatusInternalServerError,
|
||||
ErrCodeServiceUnavailable: http.StatusServiceUnavailable,
|
||||
ErrCodeGatewayTimeout: http.StatusGatewayTimeout,
|
||||
ErrCodeInvalidToken: http.StatusUnauthorized,
|
||||
ErrCodeTokenExpired: http.StatusUnauthorized,
|
||||
ErrCodeUserDisabled: http.StatusUnauthorized,
|
||||
ErrCodeOrgNotFound: http.StatusNotFound,
|
||||
ErrCodeAppNotFound: http.StatusNotFound,
|
||||
ErrCodeKnowledgeNotFound: http.StatusNotFound,
|
||||
ErrCodeInsufficientQuota: http.StatusTooManyRequests,
|
||||
ErrCodeFileTooLarge: http.StatusBadRequest,
|
||||
ErrCodeInvalidFileType: http.StatusBadRequest,
|
||||
}
|
||||
|
||||
func (e ErrCode) Status() int {
|
||||
if s, ok := httpStatusMap[e]; ok {
|
||||
return s
|
||||
}
|
||||
return http.StatusInternalServerError
|
||||
}
|
||||
|
||||
func (e ErrCode) Code() int {
|
||||
return int(e)
|
||||
}
|
||||
|
||||
func (e ErrCode) Error() string {
|
||||
return e.String()
|
||||
}
|
||||
|
||||
func (e ErrCode) String() string {
|
||||
switch e {
|
||||
case ErrCodeSuccess: return "成功"
|
||||
case ErrCodeBadRequest: return "请求参数有误"
|
||||
case ErrCodeUnauthorized: return "未授权"
|
||||
case ErrCodeForbidden: return "无权限"
|
||||
case ErrCodeNotFound: return "资源不存在"
|
||||
case ErrCodeRequestTimeout: return "请求超时"
|
||||
case ErrCodeTooManyRequests: return "请求过于频繁"
|
||||
case ErrCodeInternalError: return "服务器内部错误"
|
||||
case ErrCodeServiceUnavailable: return "服务不可用"
|
||||
case ErrCodeGatewayTimeout: return "网关超时"
|
||||
case ErrCodeInvalidToken: return "无效的认证令牌"
|
||||
case ErrCodeTokenExpired: return "认证令牌已过期"
|
||||
case ErrCodeUserDisabled: return "用户已被禁用"
|
||||
case ErrCodeOrgNotFound: return "机构不存在"
|
||||
case ErrCodeAppNotFound: return "应用不存在"
|
||||
case ErrCodeKnowledgeNotFound: return "知识库不存在"
|
||||
case ErrCodeInsufficientQuota: return "配额不足"
|
||||
case ErrCodeFileTooLarge: return "文件超出大小限制"
|
||||
case ErrCodeInvalidFileType: return "不支持的文件类型"
|
||||
default: return "未知错误"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user