Files
dify/web/utils/error-parser.ts
T
+21 0e320290e1 feat: evaluation (#35353)
Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: jyong <[email protected]>
Co-authored-by: Yansong Zhang <[email protected]>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: hj24 <[email protected]>
Co-authored-by: hj24 <[email protected]>
Co-authored-by: Joel <[email protected]>
Co-authored-by: Stephen Zhou <[email protected]>
Co-authored-by: CodingOnStar <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: 非法操作 <[email protected]>
Co-authored-by: Ayush Baluni <[email protected]>
Co-authored-by: yyh <[email protected]>
Co-authored-by: jimcody1995 <[email protected]>
Co-authored-by: James <[email protected]>
Co-authored-by: Yunlu Wen <[email protected]>
Co-authored-by: Stephen Zhou <[email protected]>
Co-authored-by: Coding On Star <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: jerryzai <[email protected]>
Co-authored-by: NVIDIAN <[email protected]>
Co-authored-by: ai-hpc <[email protected]>
Co-authored-by: Asuka Minato <[email protected]>
Co-authored-by: Junghwan <[email protected]>
Co-authored-by: HeYinKazune <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: yyh <[email protected]>
Co-authored-by: Jingyi <[email protected]>
Co-authored-by: Claude Sonnet 4.6 <[email protected]>
Co-authored-by: sxxtony <[email protected]>
2026-04-17 16:37:21 +08:00

53 lines
1.6 KiB
TypeScript

/**
* Parse plugin error message from nested error structure
* Extracts the real error message from PluginInvokeError JSON string
*
* @example
* Input: { message: "req_id: xxx PluginInvokeError: {\"message\":\"Bad credentials\"}" }
* Output: "Bad credentials"
*
* @param error - Error object (can be Response object or error with message property)
* @returns Promise<string> or string - Parsed error message
*/
export const parsePluginErrorMessage = async (error: any): Promise<string> => {
let rawMessage = ''
// Handle Response object from fetch/ky
if (error instanceof Response) {
try {
const body = await error.clone().json()
rawMessage = body?.message || error.statusText || 'Unknown error'
}
catch {
rawMessage = error.statusText || 'Unknown error'
}
}
else {
rawMessage = error?.message || error?.toString() || 'Unknown error'
}
console.log('rawMessage', rawMessage)
// Try to extract nested JSON from PluginInvokeError
// Use greedy match .+ to capture the complete JSON object with nested braces
const pluginErrorPattern = /PluginInvokeError:\s*(\{.+\})/
const match = pluginErrorPattern.exec(rawMessage)
if (match) {
try {
const errorData = JSON.parse(match[1]!)
// Return the inner message if exists
if (errorData.message)
return errorData.message
// Fallback to error_type if message not available
if (errorData.error_type)
return errorData.error_type
}
catch (parseError) {
console.warn('Failed to parse plugin error JSON:', parseError)
}
}
return rawMessage
}