{"record":{"id":"094b084cb722ef9b","repo":"iflytek/astron-agent","slug":"jsondata-message","errorCode":null,"errorMessage":"jsonData.message","messagePattern":"jsonData\\.message","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"console/frontend/src/services/database.ts","lineNumber":137,"sourceCode":"  return await http.get(\n    '/config-info/get-by-category-and-code?category=DB_TABLE_TEMPLATE&code=TB'\n  );\n}\n// 下载数据模板文件\nexport async function downloadTableTemplate(\n  params: DownloadTableTemplateParams\n): Promise<AxiosResponse<Blob>> {\n  // 这个接口返回blob文件，需要特殊处理\n  const response = await http.get('/db/table-template', {\n    params,\n    responseType: 'blob',\n  });\n  try {\n    const blob = response.data as unknown as Blob;\n    const data = await blob?.text();\n    const jsonData = JSON.parse(data);\n    // 如果可以解析为JSON，说明是错误信息\n    throw new Error(jsonData.message);\n  } catch {\n    // 不能解析为JSON，说明是正常的文件\n    return response;\n  }\n}\n// 获取库表\nexport async function allTableList(): Promise<\n  Array<{ value: string; label: string; children: unknown[] }>\n> {\n  return await http.get('/db/db_table-list');\n}\n// 导入表数据\nexport async function importFieldData(\n  params: ImportFieldDataParams\n): Promise<unknown> {\n  const formData = new FormData();\n  formData.append('file', params.file);\n","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/frontend/src/services/database.ts#L119-L155","documentation":"downloadTableTemplate downloads a template file; when the response blob is actually a JSON error body (backend returned an error instead of the file), the code parses it and throws Error(jsonData.message). The reported 'message' is whatever message field the backend error JSON carried — frequently undefined, producing the literal string 'undefined'.","triggerScenarios":"Calling the template-download endpoint while auth has expired and the gateway returns a JSON error; backend template endpoint missing/500-ing with a JSON body; wrong API path returning an error envelope instead of the Excel/CSV blob.","commonSituations":"Session timeouts during downloads (blob responses bypass axios interceptors that normally redirect to login); deployment where the template file/service isn't mounted; backend changed its error envelope so jsonData.message is absent.","solutions":["Use a fallback message: throw new Error(jsonData.message || jsonData.desc || '模板下载失败') so 'undefined' is never shown.","Route blob requests through the axios instance with responseType 'blob' and check content-type before treating data as a file.","Handle 401/403 on blob downloads by redirecting to login rather than attempting JSON.parse of the body.","Verify the template endpoint exists and returns the correct content-type in the target environment."],"exampleFix":"// before\nthrow new Error(jsonData.message);\n// after\nthrow new Error(jsonData?.message || jsonData?.desc || '模板下载失败，请稍后重试');","handlingStrategy":"try-catch","validationCode":"// check content-type before parsing blob as file\nconst contentType = response.headers?.['content-type'] || '';\nif (contentType.includes('application/json')) {\n  const err = JSON.parse(await response.data.text());\n  throw new Error(err.message || err.desc || '模板下载失败');\n}","typeGuard":"function isBlobData(d: unknown): d is Blob {\n  return d instanceof Blob && d.size > 0;\n}","tryCatchPattern":"try {\n  const blob = await downloadTableTemplate(params);\n} catch (e: any) {\n  message.error(e?.message || '模板下载失败，请重新登录后重试');\n}","preventionTips":["Check response content-type before treating data as a file","Handle 401 on blob downloads by redirecting to login (blob responses skip normal interceptors)","Always provide a fallback message — never throw jsonData.message directly","Verify the template endpoint exists in each deployment environment"],"tags":["file-download","blob","json","error-handling"],"backgroundTag":"unexpected-response-shape","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}