{"record":{"id":"4ac82bec9704330f","repo":"OpenNHP/opennhp","slug":"could-not-parse-response-body-v","errorCode":null,"errorMessage":"could not parse response body: %v","messagePattern":"could not parse response body: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"endpoints/db/utils.go","lineNumber":281,"sourceCode":"\n\tif resp.StatusCode != http.StatusOK {\n\t\tbodyBytes, _ := io.ReadAll(resp.Body)\n\n\t\treturn \"\", fmt.Errorf(\"unexpected status code: %d, content: %s\", resp.StatusCode, string(bodyBytes))\n\t}\n\n\t// read response body\n\tbodyBytes, err := io.ReadAll(resp.Body)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"could not read response body: %v\", err)\n\t}\n\n\t// parse response body\n\tvar respBody ServerResponse\n\n\terr = json.Unmarshal(bodyBytes, &respBody)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"could not parse response body: %v\", err)\n\t}\n\n\tduration := time.Since(startTime)\n\tspeed := float64(progress.TotalSize) / duration.Seconds() / (1024 * 1024)\n\n\t// change the chinese to english\n\tfmt.Printf(\"\\nUpload %s to %s success! (time: %.2fs, speed: %.2fMB/s)\\n\",\n\t\tfilePath, httpHost+respBody.FileURI, duration.Seconds(), speed)\n\n\treturn httpHost + respBody.FileURI, nil\n}\n\ntype UploadProgress struct {\n\tTotalSize   int64\n\tBytesRead   int64\n\tUploadID    string\n\tLastPercent int\n}","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/OpenNHP/opennhp/blob/6e04ca5ff03222a699c24205cd4bf8fee9af7ffe/endpoints/db/utils.go#L263-L299","documentation":"Raised in UploadFileToNHPServer after a 200 response was received and the body read succeeded: json.Unmarshal of the body into ServerResponse failed. It means the NHP server did not return the expected JSON envelope for the upload endpoint — the payload is truncated, HTML (e.g. a proxy error page), or a differently shaped JSON object.","triggerScenarios":"Thrown at endpoints/db/utils.go:281 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Capture and log the raw bodyBytes alongside the unmarshal error to see what the server actually returned","Verify the upload endpoint path and API version expected by this client match the deployed nhp-server","Check whether an intermediate proxy or gateway rewrote the response (HTML error page instead of JSON)","Confirm ServerResponse struct fields/tags match the server's response schema"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"6e04ca5ff03222a699c24205cd4bf8fee9af7ffe","analyzedAt":"2026-09-07T15:44:59.941Z","contentChangedAt":"2026-09-07T15:44:59.941Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}