{"record":{"id":"10ea5b5dab0f0e71","repo":"Tencent/WeKnora","slug":"http-decode-read-response-w","errorCode":null,"errorMessage":"http decode read response: %w","messagePattern":"http decode read response: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/infrastructure/docparser/http_parser.go","lineNumber":242,"sourceCode":"\thttpReq, err := http.NewRequestWithContext(ctx, http.MethodPost, base+PathRead, bytes.NewReader(jsonBody))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"http new request: %w\", err)\n\t}\n\thttpReq.Header.Set(\"Content-Type\", \"application/json\")\n\thttpReq.ContentLength = int64(len(jsonBody))\n\n\tresp, err := p.client.Do(httpReq)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"http read failed: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\tif resp.StatusCode != http.StatusOK {\n\t\tbodyBytes, _ := io.ReadAll(resp.Body)\n\t\treturn nil, fmt.Errorf(\"http read status %d: %s\", resp.StatusCode, string(bodyBytes))\n\t}\n\tvar out httpReadResponse\n\tif err := json.NewDecoder(resp.Body).Decode(&out); err != nil {\n\t\treturn nil, fmt.Errorf(\"http decode read response: %w\", err)\n\t}\n\treturn fromHTTPReadResponse(&out), nil\n}\n","sourceCodeStart":224,"sourceCodeEnd":246,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/infrastructure/docparser/http_parser.go#L224-L246","documentation":"This error indicates the JSON response from the HTTP document-parse service could not be decoded into the expected httpReadResponse struct. It is thrown after a successful 200 response when the body does not match the expected schema. The underlying decode error is wrapped (%w) so json syntax/type errors are preserved.","triggerScenarios":"Calling Read on the HTTP doc parser when the service returns 200 but the body is not valid JSON or lacks the expected fields (json.UnmarshalTypeError / SyntaxError).","commonSituations":"Service version mismatch where response schema changed; proxy/captive portal returning an HTML error page with 200; truncated response; wrong endpoint returning non-JSON content.","solutions":["Unwrap the error to see the exact json decode failure and offset","Check that the parser service version matches the client's expected response schema","Verify the configured URL points at the parser endpoint, not an HTML page or proxy","Log the raw response body on decode failure to diagnose schema drift"],"exampleFix":"// before\nvar out httpReadResponse\nif err := json.NewDecoder(resp.Body).Decode(&out); err != nil {\n    return nil, fmt.Errorf(\"http decode read response: %w\", err)\n}\n// after\nraw, _ := io.ReadAll(resp.Body)\nvar out httpReadResponse\nif err := json.Unmarshal(raw, &out); err != nil {\n    return nil, fmt.Errorf(\"http decode read response: %w (body=%.200q)\", err, raw)\n}","handlingStrategy":"try-catch","validationCode":"// verify endpoint returns JSON before decoding\nresp, err := http.Get(parserURL)\nif err == nil && !strings.HasPrefix(resp.Header.Get(\"Content-Type\"), \"application/json\") {\n    return fmt.Errorf(\"parser endpoint returned %s, expected JSON\", resp.Header.Get(\"Content-Type\"))\n}","typeGuard":null,"tryCatchPattern":"out, err := parser.Read(ctx, doc)\nif err != nil {\n    if strings.Contains(err.Error(), \"http decode read response\") {\n        // schema mismatch or HTML error page: log raw body, check service version\n    }\n    return err\n}","preventionTips":["Version-lock the parser service with the client","Check Content-Type header is application/json before decoding","Add schema tests covering the httpReadResponse contract","Capture raw response bodies on decode failure"],"tags":["http","json","decoding","docparser"],"backgroundTag":"json-decode-failed","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}