feat(desktop): surface baijiahao challenge-required failures with actionable copy
Baijiahao throws baijiahao_challenge_required when its risk control flags the network environment, but PublishManagementView previously showed the raw "code: ..., message: ..." string. Route the error through the existing normalizer pipeline so users see a clear "需要人机验证 + 去后台手动完成 一次发稿" prompt instead. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { describe, expect, it } from 'vitest'
|
import { describe, expect, it } from 'vitest'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
BAIJIAHAO_CHALLENGE_REQUIRED_MESSAGE,
|
||||||
PUBLISH_ACCOUNT_NOT_LOGGED_IN_MESSAGE,
|
PUBLISH_ACCOUNT_NOT_LOGGED_IN_MESSAGE,
|
||||||
QIEHAO_REAL_NAME_AUTH_MESSAGE,
|
QIEHAO_REAL_NAME_AUTH_MESSAGE,
|
||||||
WANGYIHAO_DRAFT_SAVE_PARAMETER_MESSAGE,
|
WANGYIHAO_DRAFT_SAVE_PARAMETER_MESSAGE,
|
||||||
@@ -8,6 +9,7 @@ import {
|
|||||||
WANGYIHAO_TOKEN_MISSING_MESSAGE,
|
WANGYIHAO_TOKEN_MISSING_MESSAGE,
|
||||||
WEIXIN_GZH_PUBLIC_URL_MISSING_MESSAGE,
|
WEIXIN_GZH_PUBLIC_URL_MISSING_MESSAGE,
|
||||||
isQiehaoRealNameAuthError,
|
isQiehaoRealNameAuthError,
|
||||||
|
normalizeBaijiahaoPublishErrorMessage,
|
||||||
normalizePublisherErrorMessage,
|
normalizePublisherErrorMessage,
|
||||||
normalizePublisherLoginErrorMessage,
|
normalizePublisherLoginErrorMessage,
|
||||||
normalizeQiehaoPublishErrorMessage,
|
normalizeQiehaoPublishErrorMessage,
|
||||||
@@ -76,6 +78,18 @@ describe('publisher error normalization', () => {
|
|||||||
).toBe(WANGYIHAO_PUBLISH_CLICK_MESSAGE)
|
).toBe(WANGYIHAO_PUBLISH_CLICK_MESSAGE)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('normalizes Baijiahao challenge-required failures', () => {
|
||||||
|
expect(normalizePublisherErrorMessage('baijiahao_challenge_required')).toBe(
|
||||||
|
BAIJIAHAO_CHALLENGE_REQUIRED_MESSAGE,
|
||||||
|
)
|
||||||
|
expect(
|
||||||
|
normalizePublisherErrorMessage('baijiahao_challenge_required:您所在网络环境异常,请完成验证'),
|
||||||
|
).toBe(BAIJIAHAO_CHALLENGE_REQUIRED_MESSAGE)
|
||||||
|
expect(normalizeBaijiahaoPublishErrorMessage('Error: baijiahao_challenge_required')).toBe(
|
||||||
|
BAIJIAHAO_CHALLENGE_REQUIRED_MESSAGE,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
it('normalizes Weixin GZH missing public URL failures', () => {
|
it('normalizes Weixin GZH missing public URL failures', () => {
|
||||||
expect(normalizePublisherErrorMessage('weixin_gzh_public_url_missing:100000093')).toBe(
|
expect(normalizePublisherErrorMessage('weixin_gzh_public_url_missing:100000093')).toBe(
|
||||||
WEIXIN_GZH_PUBLIC_URL_MISSING_MESSAGE,
|
WEIXIN_GZH_PUBLIC_URL_MISSING_MESSAGE,
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ export const WANGYIHAO_PUBLISH_CLICK_MESSAGE =
|
|||||||
'网易号草稿已保存,但自动发布未完成。请打开网易号后台确认草稿状态后重试。'
|
'网易号草稿已保存,但自动发布未完成。请打开网易号后台确认草稿状态后重试。'
|
||||||
export const WEIXIN_GZH_PUBLIC_URL_MISSING_MESSAGE =
|
export const WEIXIN_GZH_PUBLIC_URL_MISSING_MESSAGE =
|
||||||
'微信公众号可能已触发管理员/运营者授权发布,桌面端未能获取到文章外链。请打开公众号后台完成授权发布,并在发表记录中确认文章链接。'
|
'微信公众号可能已触发管理员/运营者授权发布,桌面端未能获取到文章外链。请打开公众号后台完成授权发布,并在发表记录中确认文章链接。'
|
||||||
|
export const BAIJIAHAO_CHALLENGE_REQUIRED_MESSAGE =
|
||||||
|
'百家号检测到网络环境异常,需要人机验证。请打开百家号后台手动完成一次发稿或验证后再重试发布。'
|
||||||
|
|
||||||
const PUBLISH_PLATFORM_LABELS: Record<string, string> = {
|
const PUBLISH_PLATFORM_LABELS: Record<string, string> = {
|
||||||
baijiahao: '百家号',
|
baijiahao: '百家号',
|
||||||
@@ -124,12 +126,27 @@ export function normalizeWeixinGzhPublishErrorMessage(
|
|||||||
return normalized
|
return normalized
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function normalizeBaijiahaoPublishErrorMessage(
|
||||||
|
message: string | null | undefined,
|
||||||
|
): string | null {
|
||||||
|
const normalized = normalizeErrorText(message)
|
||||||
|
if (!normalized) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
if (/\bbaijiahao_challenge_required\b/i.test(normalized)) {
|
||||||
|
return BAIJIAHAO_CHALLENGE_REQUIRED_MESSAGE
|
||||||
|
}
|
||||||
|
return normalized
|
||||||
|
}
|
||||||
|
|
||||||
export function normalizePublisherErrorMessage(message: string | null | undefined): string | null {
|
export function normalizePublisherErrorMessage(message: string | null | undefined): string | null {
|
||||||
if (message === 'compliance_blocked') {
|
if (message === 'compliance_blocked') {
|
||||||
return '内容合规检测已阻断本次发布,请修改文章后重新发布。'
|
return '内容合规检测已阻断本次发布,请修改文章后重新发布。'
|
||||||
}
|
}
|
||||||
const qiehaoMessage = normalizeQiehaoPublishErrorMessage(message)
|
const qiehaoMessage = normalizeQiehaoPublishErrorMessage(message)
|
||||||
const wangyihaoMessage = normalizeWangyihaoPublishErrorMessage(qiehaoMessage)
|
const wangyihaoMessage = normalizeWangyihaoPublishErrorMessage(qiehaoMessage)
|
||||||
const loginMessage = normalizePublisherLoginErrorMessage(wangyihaoMessage)
|
const baijiahaoMessage = normalizeBaijiahaoPublishErrorMessage(wangyihaoMessage)
|
||||||
|
const loginMessage = normalizePublisherLoginErrorMessage(baijiahaoMessage)
|
||||||
return normalizeWeixinGzhPublishErrorMessage(loginMessage)
|
return normalizeWeixinGzhPublishErrorMessage(loginMessage)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user