{"record":{"id":"834e4fad46cbdc8a","repo":"Tencent/WeKnora","slug":"zhipu-api-error-s-s","errorCode":null,"errorMessage":"Zhipu API error (%s): %s","messagePattern":"Zhipu API error \\((.+?)\\): (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/infrastructure/web_search/zhipu.go","lineNumber":162,"sourceCode":"\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to execute Zhipu request: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\n\trespBody, err := readZhipuResponseBody(resp.Body)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn nil, zhipuHTTPError(resp.StatusCode, respBody)\n\t}\n\n\tvar response zhipuSearchResponse\n\tif err := json.Unmarshal(respBody, &response); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to unmarshal Zhipu response: %w\", err)\n\t}\n\tif response.Error.Message != \"\" || response.Error.Code != \"\" {\n\t\treturn nil, fmt.Errorf(\"Zhipu API error (%s): %s\", response.Error.Code, response.Error.Message)\n\t}\n\n\tresults := make([]*types.WebSearchResult, 0, len(response.SearchResult))\n\tfor _, item := range response.SearchResult {\n\t\tif strings.TrimSpace(item.Title) == \"\" && strings.TrimSpace(item.Link) == \"\" {\n\t\t\tcontinue\n\t\t}\n\t\tresult := &types.WebSearchResult{\n\t\t\tTitle:   item.Title,\n\t\t\tURL:     item.Link,\n\t\t\tSnippet: item.Content,\n\t\t\tSource:  \"zhipu\",\n\t\t}\n\t\tif includeDate {\n\t\t\tif publishedAt, ok := parseZhipuDate(item.PublishDate); ok {\n\t\t\t\tresult.PublishedAt = &publishedAt\n\t\t\t}\n\t\t}","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/infrastructure/web_search/zhipu.go#L144-L180","documentation":"Zhipu returned a parseable JSON body containing an application-level error object (non-empty error.code or error.message) while the HTTP status was 200. The provider surfaces the API's own error code and message to the caller.","triggerScenarios":"Calling Search() with an invalid/over-quota API key or malformed search params when Zhipu signals the failure inside a 200 body instead of an error HTTP status.","commonSituations":"Expired or revoked Zhipu API key; exceeded rate limit/quota; unsupported search_engine value passed in the request payload.","solutions":["Check response.Error.Code against Zhipu docs (e.g. auth vs quota errors) and act accordingly","Verify the API key is valid, active, and has remaining quota","Validate the search_engine and request parameters match the current Zhipu API spec","Regenerate the API key if it was rotated or revoked"],"exampleFix":"// before\nif response.Error.Message != \"\" || response.Error.Code != \"\" {\n    return nil, fmt.Errorf(\"Zhipu API error (%s): %s\", response.Error.Code, response.Error.Message)\n}\n// after (caller side)\nvar apiErr *ZhipuAPIError\nif errors.As(err, &apiErr) && apiErr.Code == \"1301\" {\n    // refresh API key and retry once\n}","handlingStrategy":"try-catch","validationCode":"if apiKey == \"\" || len(apiKey) < 10 { return errors.New(\"zhipu api key missing or malformed\") }","typeGuard":"func isZhipuAppError(err error) (code, msg string, ok bool) {\n    if !strings.Contains(err.Error(), \"Zhipu API error (\") { return \"\", \"\", false }\n    ok = true; return\n}","tryCatchPattern":"results, err := provider.Search(ctx, q)\nif err != nil {\n    var apiErr ZhipuAPIError\n    if errors.As(err, &apiErr) && apiErr.Code == authCode { return refreshKeyAndRetry(ctx) }\n    return err\n}","preventionTips":["Rotate and validate API keys before expiry","Track quota/rate limits and back off on 429-style codes","Validate search_engine and params against the current API spec","Never assume HTTP 200 means success with this API"],"tags":["api-error","auth","zhipu","web-search"],"backgroundTag":"api-error-response","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}