{"record":{"id":"9213356d76ea8d02","repo":"SigNoz/signoz","slug":"couldn-t-unmarshal-gateway-response-into-t","errorCode":null,"errorMessage":"couldn't unmarshal gateway response into %T","messagePattern":"couldn't unmarshal gateway response into %T","errorType":"http","errorClass":"basemodel.ApiError","httpStatus":500,"severity":"error","filePath":"ee/query-service/app/api/cloudIntegrations.go","lineNumber":353,"sourceCode":"\t}\n\n\tresponse, err := client.Do(req)\n\tif err != nil {\n\t\treturn nil, basemodel.InternalError(fmt.Errorf(\"couldn't make request: %w\", err))\n\t}\n\n\tdefer response.Body.Close()\n\n\trespBody, err := io.ReadAll(response.Body)\n\tif err != nil {\n\t\treturn nil, basemodel.InternalError(fmt.Errorf(\"couldn't read response: %w\", err))\n\t}\n\n\tvar resp ResponseType\n\n\terr = json.Unmarshal(respBody, &resp)\n\tif err != nil {\n\t\treturn nil, basemodel.InternalError(fmt.Errorf(\n\t\t\t\"couldn't unmarshal gateway response into %T\", resp,\n\t\t))\n\t}\n\n\treturn &resp, nil\n}\n","sourceCodeStart":335,"sourceCodeEnd":360,"githubUrl":"https://github.com/SigNoz/signoz/blob/5069bf80b08f1f00d7e014eccc09902f9871004f/ee/query-service/app/api/cloudIntegrations.go#L335-L360","documentation":"The gateway response body was read successfully but does not JSON-decode into the expected ResponseType (the message includes the concrete Go type via %T). Field type mismatches or malformed JSON both trigger it.","triggerScenarios":"Gateway returns a payload whose shape differs from the generic response struct used by requestAndParseResponse — e.g. a string where a number is expected, or an error page body.","commonSituations":"Upstream API schema drift, gateway returning HTML/text errors with a 200 status, or a new field type changing between versions.","solutions":["Log the raw respBody alongside the target type to spot the mismatch","Compare the actual payload to the struct definition and update it","Confirm the gateway is not returning an error body with 200"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"var probe map[string]any\nif err := json.Unmarshal(body, &probe); err != nil {\n    // not JSON at all — fail before typed decode\n}","typeGuard":null,"tryCatchPattern":"Decode errors should capture the raw body and target type (%T already in the message) to pinpoint the field mismatch; fail fast rather than retry.","preventionTips":["Keep response DTOs in sync with gateway API versions","Pin versions and add contract tests for gateway schemas"],"tags":["json","parsing","gateway","upstream-api"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"5069bf80b08f1f00d7e014eccc09902f9871004f","analyzedAt":"2026-08-28T06:22:12.824Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}