iflytek/astron-agent · warning · Error

jsonData.message

Error message

jsonData.message

What it means

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'.

Solutions

  1. Use a fallback message: throw new Error(jsonData.message || jsonData.desc || '模板下载失败') so 'undefined' is never shown.
  2. Route blob requests through the axios instance with responseType 'blob' and check content-type before treating data as a file.
  3. Handle 401/403 on blob downloads by redirecting to login rather than attempting JSON.parse of the body.
  4. Verify the template endpoint exists and returns the correct content-type in the target environment.

Example fix

// before
throw new Error(jsonData.message);
// after
throw new Error(jsonData?.message || jsonData?.desc || '模板下载失败,请稍后重试');
Defensive patterns

Strategy: try-catch

Validate before calling

// check content-type before parsing blob as file
const contentType = response.headers?.['content-type'] || '';
if (contentType.includes('application/json')) {
  const err = JSON.parse(await response.data.text());
  throw new Error(err.message || err.desc || '模板下载失败');
}

Type guard

function isBlobData(d: unknown): d is Blob {
  return d instanceof Blob && d.size > 0;
}

Try / catch

try {
  const blob = await downloadTableTemplate(params);
} catch (e: any) {
  message.error(e?.message || '模板下载失败,请重新登录后重试');
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12). Data as JSON: /api/errors/094b084cb722ef9b. Report an issue: GitHub.

Appendix: source

Thrown at console/frontend/src/services/database.ts:137

  return await http.get(
    '/config-info/get-by-category-and-code?category=DB_TABLE_TEMPLATE&code=TB'
  );
}
// 下载数据模板文件
export async function downloadTableTemplate(
  params: DownloadTableTemplateParams
): Promise<AxiosResponse<Blob>> {
  // 这个接口返回blob文件,需要特殊处理
  const response = await http.get('/db/table-template', {
    params,
    responseType: 'blob',
  });
  try {
    const blob = response.data as unknown as Blob;
    const data = await blob?.text();
    const jsonData = JSON.parse(data);
    // 如果可以解析为JSON,说明是错误信息
    throw new Error(jsonData.message);
  } catch {
    // 不能解析为JSON,说明是正常的文件
    return response;
  }
}
// 获取库表
export async function allTableList(): Promise<
  Array<{ value: string; label: string; children: unknown[] }>
> {
  return await http.get('/db/db_table-list');
}
// 导入表数据
export async function importFieldData(
  params: ImportFieldDataParams
): Promise<unknown> {
  const formData = new FormData();
  formData.append('file', params.file);

View on GitHub (pinned to 5e758547a8)