{"record":{"id":"a6c50ff108de43e2","repo":"flipped-aurora/gin-vue-admin","slug":"code-d-msg-s-body-s","errorCode":null,"errorMessage":"大模型服务返回业务错误: code=%d msg=%s body=%s","messagePattern":"大模型服务返回业务错误: code=(.+?) msg=(.+?) body=(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/service/system/auto_code_llm.go","lineNumber":54,"sourceCode":"\n\tbody, err := io.ReadAll(res.Body)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"读取大模型响应失败: %w\", err)\n\t}\n\n\tbodyPreview := previewResponseBody(body)\n\tcontentType := res.Header.Get(\"Content-Type\")\n\tif res.StatusCode < 200 || res.StatusCode >= 300 {\n\t\treturn nil, fmt.Errorf(\"上游大模型服务返回非 2xx: status=%d content-type=%s body=%s\", res.StatusCode, contentType, bodyPreview)\n\t}\n\n\tvar resStruct commonResp.Response\n\tif err = json.Unmarshal(body, &resStruct); err != nil {\n\t\treturn nil, fmt.Errorf(\"解析大模型响应失败: status=%d content-type=%s body=%s err=%w\", res.StatusCode, contentType, bodyPreview, err)\n\t}\n\n\tif resStruct.Code != commonResp.SUCCESS {\n\t\treturn nil, fmt.Errorf(\"大模型服务返回业务错误: code=%d msg=%s body=%s\", resStruct.Code, resStruct.Msg, bodyPreview)\n\t}\n\n\treturn resStruct.Data, nil\n}\n\nfunc (s *AutoCodeService) LLMAutoStream(ctx context.Context, llm common.JSONMap) (*http.Response, error) {\n\tpath, err := buildLLMAutoPath(llm)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tpayload := cloneLLMAutoJSONMap(llm)\n\tresponseMode := strings.ToLower(strings.TrimSpace(fmt.Sprintf(\"%v\", payload[\"response_mode\"])))\n\tif responseMode == \"\" {\n\t\tpayload[\"response_mode\"] = \"streaming\"\n\t}\n\n\tres, err := request.HttpRequestWithContextAndTimeout(","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/service/system/auto_code_llm.go#L36-L72","documentation":"When the body parses into commonResp.Response but its Code field does not equal commonResp.SUCCESS, LLMAuto treats it as an application-level business error from the LLM service and surfaces code, msg, and a body preview. The HTTP layer succeeded but the upstream reported failure inside its envelope.","triggerScenarios":"Upstream returns 200 with {code: != SUCCESS, msg: ...} — e.g. invalid token in the envelope, model access denied, quota exceeded reported at the application layer, or prompt/params rejected by the LLM backend.","commonSituations":"Expired upstream access token still yielding HTTP 200, insufficient account balance/quota on the LLM platform, disallowed model for the account, prompt flagged by content moderation returning a business error code.","solutions":["Read msg/body in the error to get the upstream's business reason","Fix credentials/quota on the LLM provider account as indicated by the code/msg","If the model is disallowed, switch llm config to a model the account can access","Map recurring upstream business codes to friendlier messages in your API layer"],"exampleFix":"// before: raw passthrough of upstream business error\nreturn nil, fmt.Errorf(\"大模型服务返回业务错误: code=%d msg=%s\", resStruct.Code, resStruct.Msg)\n// after: map known codes for callers\nswitch resStruct.Code {\ncase codeQuotaExceeded:\n    return nil, fmt.Errorf(\"LLM 额度不足，请充值后重试 (code=%d)\", resStruct.Code)\ndefault:\n    return nil, fmt.Errorf(\"大模型服务返回业务错误: code=%d msg=%s\", resStruct.Code, resStruct.Msg)\n}","handlingStrategy":"fallback","validationCode":null,"typeGuard":"func isBusinessError(resp commonResp.Response) bool {\n    return resp.Code != commonResp.SUCCESS\n}","tryCatchPattern":"data, err := svc.LLMAuto(ctx, llmCfg)\nif err != nil {\n    var bizErr *UpstreamBizError\n    if errors.As(err, &bizErr) {\n        // switch to fallback model/provider or surface bizErr.Code/Msg to the user\n    }\n    return err\n}","preventionTips":["Pre-check provider account quota/token validity before bulk code-gen runs","Configure a fallback model or provider for business-level rejections","Map upstream business codes to user-facing messages in one place","Alert on recurring non-SUCCESS codes so credential/quota issues surface early"],"tags":["llm","api-contract","business-error","upstream"],"backgroundTag":"upstream-business-error","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}