feat(dongchedi): translate platform "server exception" into actionable copy

Map dongchedi adapter failures (raw "server exception" or
dongchedi_platform_exception) to a Chinese prompt steering the user to
the dongchedi backend, so renderer/admin views and desktop-task error
payloads no longer surface the opaque platform message.
This commit is contained in:
2026-05-11 12:26:38 +08:00
parent f34c6f2ceb
commit 6fa9a6c052
8 changed files with 164 additions and 13 deletions
@@ -20,18 +20,26 @@ func normalizePublishRecordForResponse(item *PublishRecordResponse) {
}
func normalizePublishRecordErrorMessage(platform string, message *string) *string {
if strings.TrimSpace(platform) != "baijiahao" || message == nil {
normalizedPlatform := strings.TrimSpace(platform)
if message == nil || (normalizedPlatform != "baijiahao" && normalizedPlatform != "dongchedi") {
return message
}
trimmed := strings.TrimSpace(*message)
if trimmed == "baijiahao_challenge_required" ||
if normalizedPlatform == "baijiahao" && (trimmed == "baijiahao_challenge_required" ||
trimmed == "desktop_account_risk_control" ||
trimmed == "desktop_account_challenge_required" ||
strings.HasPrefix(trimmed, "baijiahao_challenge_required:") {
strings.HasPrefix(trimmed, "baijiahao_challenge_required:")) {
normalized := baijiahaoRiskControlPrompt
return &normalized
}
if normalizedPlatform == "dongchedi" && (trimmed == "dongchedi_platform_exception" ||
strings.EqualFold(trimmed, "server exception") ||
strings.HasPrefix(trimmed, "dongchedi_publish_failed:server exception") ||
strings.HasPrefix(trimmed, "dongchedi_draft_failed:server exception")) {
normalized := dongchediPlatformExceptionPrompt
return &normalized
}
return message
}
@@ -467,6 +467,7 @@ func extractStringPointer(payload map[string]any, keys ...string) *string {
}
const baijiahaoRiskControlPrompt = "您触发平台风控,请手动发稿一篇并完成验证,方可继续使用"
const dongchediPlatformExceptionPrompt = "懂车帝平台返回异常,请打开懂车帝后台查看并处理平台提示,确认账号状态后再重试。"
func desktopTaskErrorMessage(payload map[string]any, platform string) *string {
if message := desktopTaskPlatformErrorMessage(payload, platform); message != nil {
@@ -485,7 +486,8 @@ func desktopTaskErrorMessage(payload map[string]any, platform string) *string {
}
func desktopTaskPlatformErrorMessage(payload map[string]any, platform string) *string {
if strings.TrimSpace(platform) != "baijiahao" {
normalizedPlatform := strings.TrimSpace(platform)
if normalizedPlatform != "baijiahao" && normalizedPlatform != "dongchedi" {
return nil
}
@@ -495,13 +497,22 @@ func desktopTaskPlatformErrorMessage(payload map[string]any, platform string) *s
continue
}
trimmed := strings.TrimSpace(*value)
if trimmed == "baijiahao_challenge_required" ||
trimmed == "desktop_account_risk_control" ||
trimmed == "desktop_account_challenge_required" ||
strings.HasPrefix(trimmed, "baijiahao_challenge_required:") {
if normalizedPlatform == "baijiahao" &&
(trimmed == "baijiahao_challenge_required" ||
trimmed == "desktop_account_risk_control" ||
trimmed == "desktop_account_challenge_required" ||
strings.HasPrefix(trimmed, "baijiahao_challenge_required:")) {
message := baijiahaoRiskControlPrompt
return &message
}
if normalizedPlatform == "dongchedi" &&
(trimmed == "dongchedi_platform_exception" ||
strings.EqualFold(trimmed, "server exception") ||
strings.HasPrefix(trimmed, "dongchedi_publish_failed:server exception") ||
strings.HasPrefix(trimmed, "dongchedi_draft_failed:server exception")) {
message := dongchediPlatformExceptionPrompt
return &message
}
}
return nil
@@ -43,6 +43,36 @@ func TestDesktopTaskErrorMessageKeepsGenericMessage(t *testing.T) {
}
}
func TestDesktopTaskErrorMessageMapsDongchediServerException(t *testing.T) {
tests := []struct {
name string
payload map[string]any
}{
{
name: "raw platform message",
payload: map[string]any{
"message": "server exception",
},
},
{
name: "adapter code",
payload: map[string]any{
"code": "dongchedi_platform_exception",
"message": "懂车帝平台返回异常,请打开懂车帝后台查看并处理平台提示,确认账号状态后再重试。",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := desktopTaskErrorMessage(tt.payload, "dongchedi")
if got == nil || *got != dongchediPlatformExceptionPrompt {
t.Fatalf("desktopTaskErrorMessage() = %v, want %q", got, dongchediPlatformExceptionPrompt)
}
})
}
}
func TestNormalizePublishRecordForResponseUsesBaijiahaoPublicURL(t *testing.T) {
articleID := "1863525130677225913"
editURL := "https://baijiahao.baidu.com/builder/rc/edit?type=news&article_id=1863525130677225913"
@@ -64,6 +94,20 @@ func TestNormalizePublishRecordForResponseUsesBaijiahaoPublicURL(t *testing.T) {
}
}
func TestNormalizePublishRecordForResponseMapsDongchediServerException(t *testing.T) {
rawError := "server exception"
item := &PublishRecordResponse{
PlatformID: "dongchedi",
ErrorMessage: &rawError,
}
normalizePublishRecordForResponse(item)
if item.ErrorMessage == nil || *item.ErrorMessage != dongchediPlatformExceptionPrompt {
t.Fatalf("ErrorMessage = %v, want %q", item.ErrorMessage, dongchediPlatformExceptionPrompt)
}
}
func TestNormalizePublishRecordForResponseUsesWangyihaoPublicURL(t *testing.T) {
articleID := "IK5K461I05561G2M"
item := &PublishRecordResponse{