Files
tyapi-server/internal/application/api/utils/error_translator.go
2025-07-30 00:51:22 +08:00

41 lines
1.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package utils
// TranslateErrorMsg 翻译错误信息
func TranslateErrorMsg(errorType, errorMsg *string) *string {
if errorType == nil || errorMsg == nil {
return nil
}
// 错误类型到中文描述的映射
errorTypeTranslations := map[string]string{
"invalid_access": "无效的访问凭证",
"frozen_account": "账户已被冻结",
"invalid_ip": "IP地址未授权",
"arrears": "账户余额不足",
"not_subscribed": "未订阅该产品",
"product_not_found": "产品不存在",
"product_disabled": "产品已停用",
"system_error": "接口异常",
"datasource_error": "数据源异常",
"invalid_param": "参数校验失败",
"decrypt_fail": "参数解密失败",
"query_empty": "查询结果为空",
}
// 获取错误类型的中文描述
translatedType, exists := errorTypeTranslations[*errorType]
if !exists {
// 如果没有找到对应的翻译,返回原始错误信息
return errorMsg
}
// 构建翻译后的错误信息
translatedMsg := translatedType
if *errorMsg != "" && *errorMsg != *errorType {
// 如果原始错误信息不是错误类型本身,则组合显示
translatedMsg = translatedType + "" + *errorMsg
}
return &translatedMsg
}