{"record":{"id":"0d794fde7b58512b","repo":"fish2018/pansou","slug":"s-api-s-0d794f","errorCode":null,"errorMessage":"[%s] API返回错误: %s","messagePattern":"\\[(.+?)\\] API返回错误: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/ouge/ouge.go","lineNumber":159,"sourceCode":"\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"[%s] 搜索请求失败: %w\", p.Name(), err)\n\t}\n\tdefer resp.Body.Close()\n\t\n\t// 解析JSON响应\n\tbody, err := io.ReadAll(resp.Body)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"[%s] 读取响应失败: %w\", p.Name(), err)\n\t}\n\t\n\tvar apiResponse OugeAPIResponse\n\tif err := json.Unmarshal(body, &apiResponse); err != nil {\n\t\treturn nil, fmt.Errorf(\"[%s] 解析JSON响应失败: %w\", p.Name(), err)\n\t}\n\t\n\t// 检查API响应状态\n\tif apiResponse.Code != 1 {\n\t\treturn nil, fmt.Errorf(\"[%s] API返回错误: %s\", p.Name(), apiResponse.Msg)\n\t}\n\t\n\t// 解析搜索结果\n\tvar results []model.SearchResult\n\tfor _, item := range apiResponse.List {\n\t\tif result := p.parseAPIItem(item); result.Title != \"\" {\n\t\t\tresults = append(results, result)\n\t\t}\n\t}\n\t\n\treturn results, nil\n}\n\n// OugeAPIResponse API响应结构\ntype OugeAPIResponse struct {\n\tCode      int           `json:\"code\"`\n\tMsg       string        `json:\"msg\"`\n\tPage      int           `json:\"page\"`","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/ouge/ouge.go#L141-L177","documentation":"Application-level error: the ouge API responded with valid JSON whose code field is not 1, so the plugin surfaces apiResponse.Msg as the failure reason. This is the upstream API explicitly reporting an error (auth failure, bad parameters, quota, internal error) rather than a transport problem.","triggerScenarios":"searchImpl gets a 200 with parsed JSON where apiResponse.Code != 1; the message text in apiResponse.Msg carries the upstream reason.","commonSituations":"API key/token expired server-side; search keyword rejected by upstream; upstream service degraded and returns code!=1 with an error message; undocumented code values added by an API version change.","solutions":["Log apiResponse.Msg verbatim — it is the upstream-provided diagnosis","Check whether the request parameters (keyword encoding, pagination) are accepted by the upstream API","Verify any credentials/token the API expects are still valid","Handle specific code values distinctly if the API documents them (rate limit vs auth vs server error)"],"exampleFix":"// before\nif apiResponse.Code != 1 {\n    return nil, fmt.Errorf(\"[%s] API返回错误: %s\", p.Name(), apiResponse.Msg)\n}\n// after\nif apiResponse.Code != 1 {\n    if apiResponse.Code == 429 { return nil, errRateLimited }\n    return nil, fmt.Errorf(\"[%s] API返回错误 code=%d: %s\", p.Name(), apiResponse.Code, apiResponse.Msg)\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err != nil {\n    if strings.Contains(err.Error(), \"API返回错误\") {\n        // upstream explicitly refused: don't blind-retry, surface msg to user\n        return fmt.Errorf(\"upstream rejected search: %w\", err)\n    }\n    return err\n}","preventionTips":["Distinguish business errors (code!=1) from transport errors before retrying","Surface apiResponse.Msg to operators — it contains the upstream diagnosis","Track code values over time to catch API version changes","Avoid retrying when the message indicates auth or bad-parameter errors"],"tags":["api","upstream","plugin","business-error"],"backgroundTag":"api-error-response","analyzedSha":"beaa56133755a548ebc51b090b3816e2ae044aa6","analyzedAt":"2026-09-07T00:31:18.025Z","contentChangedAt":"2026-09-07T00:31:18.025Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}