{"record":{"id":"a2d5e681fb18d43e","repo":"jeecgboot/JeecgBoot","slug":"sys-api-apirequestfailed","errorCode":null,"errorMessage":"sys.api.apiRequestFailed","messagePattern":"sys\\.api\\.apiRequestFailed","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"jeecgboot-vue3/src/utils/http/axios/index.ts","lineNumber":50,"sourceCode":"   */\n  transformRequestHook: (res: AxiosResponse<Result>, options: RequestOptions) => {\n    const { t } = useI18n();\n    const { isTransformResponse, isReturnNativeResponse } = options;\n    // 是否返回原生响应头 比如：需要获取响应头时使用该属性\n    if (isReturnNativeResponse) {\n      return res;\n    }\n    // 不进行任何处理，直接返回\n    // 用于页面代码可能需要直接获取code，data，message这些信息时开启\n    if (!isTransformResponse) {\n      return res.data;\n    }\n    // 错误的时候返回\n\n    const { data } = res;\n    if (!data) {\n      // return '[HTTP] Request has no return value';\n      throw new Error(t('sys.api.apiRequestFailed'));\n    }\n    //  这里 code，result，message为 后台统一的字段，需要在 types.ts内修改为项目自己的接口返回格式\n    const { code, result, message, success } = data;\n    // 这里逻辑可以根据项目进行修改\n    const hasSuccess = data && Reflect.has(data, 'code') && (code === ResultEnum.SUCCESS || code === 200);\n    if (hasSuccess) {\n      if (success && message && options.successMessageMode === 'success') {\n        //信息成功提示\n        createMessage.success(message);\n      }\n      return result;\n    }\n\n    // 在此处根据自己项目的实际情况对不同的code执行不同的操作\n    // 如果不希望中断当前请求，请return数据，否则直接抛出异常即可\n    let timeoutMsg = '';\n    switch (code) {\n      case ResultEnum.TIMEOUT:","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/jeecgboot/JeecgBoot/blob/96fb33f5ec68516da0b0147da06b2eb0419e063a/jeecgboot-vue3/src/utils/http/axios/index.ts#L32-L68","documentation":"This throw lives in the Axios transformRequestHook (the response interceptor). After stripping the native response, it expects res.data to be truthy. If the HTTP response body is empty or null (e.g. a 204 No Content, an empty 200, or a proxy returning nothing), data is falsy and it throws the generic i18n key 'sys.api.apiRequestFailed'. This is the 'no return value at all' branch, distinct from the later non-success-code branch (error 10).","triggerScenarios":"Backend returns an empty body with HTTP 200; a server/proxy strips the body; a streaming endpoint closes before writing; a mock returns undefined; the response is a 204 No Content but isTransformResponse is true (the default). The throw only occurs when isTransformResponse is true (default) and isReturnNativeResponse is false.","commonSituations":"Calling an endpoint that legitimately returns no body (DELETE, health-check, no-content acknowledgements) through the default defHttp config; misconfigured nginx/gateway dropping the body; backend exception handlers returning ResponseEntity with no body; mock setup returning {} from the mock adapter but the interceptor seeing null.","solutions":["For endpoints that legitimately return no body, call defHttp with { isTransformResponse: false } so the raw response passes through.","Ensure the backend always returns a JSON envelope { code, result, message } even for empty results.","Check the network tab for the actual response body — confirm the gateway isn't stripping it.","If using mocks, return a proper Result-shaped object, not undefined."],"exampleFix":"// before — default transform expects a body\ndefHttp.get({ url: '/api/acknowledge' }); // 204 -> throws\n\n// after — bypass transform for no-body endpoints\ndefHttp.get({ url: '/api/acknowledge' }, { isTransformResponse: false });","handlingStrategy":"validation","validationCode":"// For endpoints that may return no body, bypass the transform\nawait defHttp.get(\n  { url: '/api/no-content' },\n  { isTransformResponse: false }\n);","typeGuard":null,"tryCatchPattern":"try {\n  const data = await defHttp.get({ url: '/api/x' });\n} catch (e) {\n  // empty-body or non-success; check e.message for the i18n key\n  if (e.message === t('sys.api.apiRequestFailed')) { /* empty body */ }\n}","preventionTips":["Use isTransformResponse:false for no-content endpoints.","Ensure the backend always returns a JSON envelope.","Verify mock adapters return proper Result objects."],"tags":["http","axios","response-transform","frontend","api"],"backgroundTag":null,"analyzedSha":"96fb33f5ec68516da0b0147da06b2eb0419e063a","analyzedAt":"2026-08-14T00:04:16.786Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}