feat: enhance error handling with internationalized messages across services and locales

This commit is contained in:
mlogclub
2026-06-02 21:10:17 +08:00
parent 0b4a1b4594
commit 5b6c54de34
14 changed files with 109 additions and 42 deletions
+2 -1
View File
@@ -1,6 +1,7 @@
package params
import (
"agent-desk/internal/pkg/errorsx"
"errors"
"fmt"
"log/slog"
@@ -182,7 +183,7 @@ func FormValue(ctx *gin.Context, name string) string {
func FormValueRequired(ctx *gin.Context, name string) (string, error) {
str := FormValue(ctx, name)
if len(str) == 0 {
return "", errors.New("参数:" + name + "不能为空")
return "", errorsx.InvalidParamI18n("error.param.required", name)
}
return str, nil
}
+33
View File
@@ -356,3 +356,36 @@ error.mcp.callToolFailed: "Failed to call MCP tool: %v"
error.mcp.connectServerFailed: "Failed to connect to MCP Server: %v"
error.wxwork.unsupportedOutboundMessageType: "Unsupported WeCom outbound message type: %s"
error.wxwork.currentUnsupportedOutboundMessageType: "The current WeCom outbound message type is not supported yet: %s"
error.param.required: "Parameter %s is required."
error.oidc.loginDisabled: "OIDC login is not enabled."
error.oidc.stateSecretMissing: "OIDC login secret is not configured."
error.oidc.profileMissing: "OIDC user information does not exist."
error.oidc.bindingDisabled: "The current OIDC binding has been disabled."
error.oidc.boundUserMissing: "The system user bound to this OIDC account does not exist."
error.wxwork.loginDisabled: "WeCom login is not enabled."
error.wxwork.loginSecretMissing: "WeCom login secret is not configured."
error.wxwork.profileMissing: "WeCom user information does not exist."
error.wxwork.bindingDisabled: "The current WeCom binding has been disabled."
error.wxwork.boundUserMissing: "The system user bound to this WeCom account does not exist."
error.wxwork.userIDMissing: "Failed to get the WeCom user ID."
error.wxwork.userIDTaken: "The WeCom user ID is already used as a system username."
error.wxwork.mobileTaken: "The WeCom mobile number is already used by a system user."
error.wxwork.emailTaken: "The WeCom email address is already used by a system user."
error.wxwork.configIncomplete: "WeCom is not enabled or its configuration is incomplete."
error.customerSession.secretMissing: "Customer session secret is not configured."
error.conversation.createFailed: "Failed to create conversation."
error.conversation.tagNotFound: "Tag not found."
error.aiConfig.noneEnabled: "No available AI configuration is configured."
error.embeddingModel.noneEnabled: "No available Embedding model is configured."
error.agentTeamSchedule.startAtInvalid: "Invalid start time format."
error.agentTeamSchedule.startAtInvalidWithFormat: "Invalid start time format. Use yyyy-MM-dd HH:mm:ss or RFC3339."
error.agentTeamSchedule.endAtInvalid: "Invalid end time format."
error.agentTeamSchedule.endAtInvalidWithFormat: "Invalid end time format. Use yyyy-MM-dd HH:mm:ss or RFC3339."
error.agentTeamSchedule.startDateInvalid: "Invalid start date format."
error.agentTeamSchedule.startDateInvalidWithFormat: "Invalid start date format. Use yyyy-MM-dd."
error.agentTeamSchedule.endDateInvalid: "Invalid end date format."
error.agentTeamSchedule.endDateInvalidWithFormat: "Invalid end date format. Use yyyy-MM-dd."
error.agentTeamSchedule.startTimeInvalid: "Invalid start time format."
error.agentTeamSchedule.startTimeInvalidWithFormat: "Invalid start time format. Use HH:mm or HH:mm:ss."
error.agentTeamSchedule.endTimeInvalid: "Invalid end time format."
error.agentTeamSchedule.endTimeInvalidWithFormat: "Invalid end time format. Use HH:mm or HH:mm:ss."
+33
View File
@@ -356,3 +356,36 @@ error.mcp.callToolFailed: "调用 MCP 工具失败: %v"
error.mcp.connectServerFailed: "连接 MCP Server 失败: %v"
error.wxwork.unsupportedOutboundMessageType: "不支持的企业微信下行消息类型: %s"
error.wxwork.currentUnsupportedOutboundMessageType: "当前暂不支持企业微信下行消息类型: %s"
error.param.required: "参数:%s不能为空"
error.oidc.loginDisabled: "OIDC 登录未启用"
error.oidc.stateSecretMissing: "OIDC 登录密钥未配置"
error.oidc.profileMissing: "OIDC 用户信息不存在"
error.oidc.bindingDisabled: "当前 OIDC 绑定已停用"
error.oidc.boundUserMissing: "OIDC 账号绑定的系统用户不存在"
error.wxwork.loginDisabled: "企业微信登录未启用"
error.wxwork.loginSecretMissing: "企业微信登录密钥未配置"
error.wxwork.profileMissing: "企业微信用户信息不存在"
error.wxwork.bindingDisabled: "当前企业微信绑定已停用"
error.wxwork.boundUserMissing: "企业微信账号绑定的系统用户不存在"
error.wxwork.userIDMissing: "企业微信用户ID获取失败"
error.wxwork.userIDTaken: "企业微信用户ID已被系统用户名占用"
error.wxwork.mobileTaken: "企业微信手机号已被系统用户占用"
error.wxwork.emailTaken: "企业微信邮箱已被系统用户占用"
error.wxwork.configIncomplete: "企业微信未启用或配置不完整"
error.customerSession.secretMissing: "客服会话密钥未配置"
error.conversation.createFailed: "创建会话失败"
error.conversation.tagNotFound: "标签不存在"
error.aiConfig.noneEnabled: "未配置可用的 AI 配置"
error.embeddingModel.noneEnabled: "未配置可用的 Embedding 模型"
error.agentTeamSchedule.startAtInvalid: "开始时间格式错误"
error.agentTeamSchedule.startAtInvalidWithFormat: "开始时间格式错误,请使用 yyyy-MM-dd HH:mm:ss 或 RFC3339"
error.agentTeamSchedule.endAtInvalid: "结束时间格式错误"
error.agentTeamSchedule.endAtInvalidWithFormat: "结束时间格式错误,请使用 yyyy-MM-dd HH:mm:ss 或 RFC3339"
error.agentTeamSchedule.startDateInvalid: "开始日期格式错误"
error.agentTeamSchedule.startDateInvalidWithFormat: "开始日期格式错误,请使用 yyyy-MM-dd"
error.agentTeamSchedule.endDateInvalid: "结束日期格式错误"
error.agentTeamSchedule.endDateInvalidWithFormat: "结束日期格式错误,请使用 yyyy-MM-dd"
error.agentTeamSchedule.startTimeInvalid: "开始时间格式错误"
error.agentTeamSchedule.startTimeInvalidWithFormat: "开始时间格式错误,请使用 HH:mm 或 HH:mm:ss"
error.agentTeamSchedule.endTimeInvalid: "结束时间格式错误"
error.agentTeamSchedule.endTimeInvalidWithFormat: "结束时间格式错误,请使用 HH:mm 或 HH:mm:ss"