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
@@ -2,6 +2,7 @@ import { describe, expect, it } from 'vitest'
import {
BAIJIAHAO_CHALLENGE_REQUIRED_MESSAGE,
DONGCHEDI_PLATFORM_EXCEPTION_MESSAGE,
PUBLISH_ACCOUNT_NOT_LOGGED_IN_MESSAGE,
QIEHAO_REAL_NAME_AUTH_MESSAGE,
WANGYIHAO_DRAFT_SAVE_PARAMETER_MESSAGE,
@@ -10,6 +11,7 @@ import {
WEIXIN_GZH_PUBLIC_URL_MISSING_MESSAGE,
isQiehaoRealNameAuthError,
normalizeBaijiahaoPublishErrorMessage,
normalizeDongchediPublishErrorMessage,
normalizePublisherErrorMessage,
normalizePublisherLoginErrorMessage,
normalizeQiehaoPublishErrorMessage,
@@ -99,6 +101,18 @@ describe('publisher error normalization', () => {
)
})
it('normalizes Dongchedi server exception failures to a broad platform prompt', () => {
expect(normalizePublisherErrorMessage('server exception', 'dongchedi')).toBe(
DONGCHEDI_PLATFORM_EXCEPTION_MESSAGE,
)
expect(normalizePublisherErrorMessage('dongchedi_publish_failed:server exception')).toBe(
DONGCHEDI_PLATFORM_EXCEPTION_MESSAGE,
)
expect(normalizeDongchediPublishErrorMessage('Error: dongchedi_platform_exception')).toBe(
DONGCHEDI_PLATFORM_EXCEPTION_MESSAGE,
)
})
it('leaves unknown publisher errors unchanged', () => {
expect(normalizePublisherErrorMessage('qiehao_publish_failed')).toBe('qiehao_publish_failed')
})
@@ -12,6 +12,8 @@ export const WEIXIN_GZH_PUBLIC_URL_MISSING_MESSAGE =
'微信公众号可能已触发管理员/运营者授权发布,桌面端未能获取到文章外链。请打开公众号后台完成授权发布,并在发表记录中确认文章链接。'
export const BAIJIAHAO_CHALLENGE_REQUIRED_MESSAGE =
'百家号检测到网络环境异常,需要人机验证。请打开百家号后台手动完成一次发稿或验证后再重试发布。'
export const DONGCHEDI_PLATFORM_EXCEPTION_MESSAGE =
'懂车帝平台返回异常,请打开懂车帝后台查看并处理平台提示,确认账号状态后再重试。'
const PUBLISH_PLATFORM_LABELS: Record<string, string> = {
baijiahao: '百家号',
@@ -34,6 +36,10 @@ function normalizeErrorText(value: string | null | undefined): string | null {
return trimmed ? trimmed : null
}
function isDongchediPlatform(platform?: string | null): boolean {
return platform?.trim().toLowerCase() === 'dongchedi'
}
export function isQiehaoRealNameAuthError(
message: string | null | undefined,
code?: number | string | null,
@@ -140,13 +146,39 @@ export function normalizeBaijiahaoPublishErrorMessage(
return normalized
}
export function normalizePublisherErrorMessage(message: string | null | undefined): string | null {
export function normalizeDongchediPublishErrorMessage(
message: string | null | undefined,
platform?: string | null,
): string | null {
const normalized = normalizeErrorText(message)
if (!normalized) {
return null
}
const hasDongchediSignal =
isDongchediPlatform(platform) || /\bdongchedi_(?:draft|publish|platform)_/i.test(normalized)
if (
hasDongchediSignal &&
(/\bserver[\s_-]*exception\b/i.test(normalized) ||
/\bdongchedi_platform_exception\b/i.test(normalized))
) {
return DONGCHEDI_PLATFORM_EXCEPTION_MESSAGE
}
return normalized
}
export function normalizePublisherErrorMessage(
message: string | null | undefined,
platform?: string | null,
): string | null {
if (message === 'compliance_blocked') {
return '内容合规检测已阻断本次发布,请修改文章后重新发布。'
}
const qiehaoMessage = normalizeQiehaoPublishErrorMessage(message)
const wangyihaoMessage = normalizeWangyihaoPublishErrorMessage(qiehaoMessage)
const baijiahaoMessage = normalizeBaijiahaoPublishErrorMessage(wangyihaoMessage)
const loginMessage = normalizePublisherLoginErrorMessage(baijiahaoMessage)
const dongchediMessage = normalizeDongchediPublishErrorMessage(baijiahaoMessage, platform)
const loginMessage = normalizePublisherLoginErrorMessage(dongchediMessage)
return normalizeWeixinGzhPublishErrorMessage(loginMessage)
}