MCPcopy Create free account
hub / github.com/Rfym21/Qwen2API / parseUpstreamImageError

Function parseUpstreamImageError

src/controllers/chat.image.video.js:93–139  ·  view source on GitHub ↗
(data)

Source from the content-addressed store, hash-verified

91 raw_response_body: rawPayload
92 })
93 return {
94 error: `当前账号的该功能使用次数已达上限,${waitHours ? `请等待约 ${waitHours} 小时后再试` : '请稍后再试'}`,
95 code: errorData.code,
96 wait_hours: waitHours,
97 status: 429
98 }
99 }
100
101 logger.error('请求上游服务时出现错误', 'CHAT', '', {
102 parsed_error: errorData,
103 raw_response_body: rawPayload
104 })
105 return {
106 error: errorData.details || errorData.code || 'Service error, please try again later',
107 code: errorData.code,
108 request_id: payload.request_id,
109 status: errorData.code === 'Bad_Request' && /internal error/i.test(errorData.details || '') ? 502 : 500
110 }
111 } catch (e) {
112 return null
113 }
114}
115
116const parseUpstreamImageErrorFromText = (text) => {
117 try {
118 if (!text || typeof text !== 'string') {
119 return null
120 }
121
122 // 图片接口在额度耗尽时可能返回普通 JSON 文本而不是 SSE,需要在流结束后补做一次识别
123 return parseUpstreamImageError(JSON.parse(text))
124 } catch (e) {
125 return null
126 }
127}
128
129/**
130 * 收集对象中的所有值
131 * @param {*} payload - 任意负载
132 * @param {Set<object>} visited - 已访问对象集合
133 * @returns {Array<*>} 所有嵌套值
134 */
135const collectNestedValues = (payload, visited = new Set()) => {
136 if (!payload || typeof payload !== 'object') {
137 return []
138 }
139
140 if (visited.has(payload)) {
141 return []
142 }

Callers 5

readVideoUpstreamResultFunction · 0.85
applyPayloadFunction · 0.85
readImageUpstreamResultFunction · 0.85
generateImageVideoResultFunction · 0.85

Calls 2

formatPayloadForLogFunction · 0.85
errorMethod · 0.80

Tested by

no test coverage detected