{"record":{"id":"caba9cdc20fd7bdf","repo":"googleapis/mcp-toolbox","slug":"unexpected-status-code-d-s","errorCode":null,"errorMessage":"unexpected status code: %d (%s)","messagePattern":"unexpected status code: (.+?) \\((.+?)\\)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/http/http.go","lineNumber":230,"sourceCode":"\tvar body []byte\n\tbody, err = io.ReadAll(resp.Body)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif resp.StatusCode < 200 || resp.StatusCode > 299 {\n\t\tif s.ReturnFullError {\n\t\t\treturn nil, fmt.Errorf(\"unexpected status code: %d, response body: %s\", resp.StatusCode, string(body))\n\t\t}\n\n\t\tlogger, err := util.LoggerFromContext(ctx)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"unable to get logger from ctx: %s\", err)\n\t\t}\n\t\tlogger.DebugContext(ctx, \"http source upstream error\", \"status\", resp.StatusCode, \"body\", truncateForLog(body, maxErrorBodyLogBytes))\n\n\t\tstatusText := http.StatusText(resp.StatusCode)\n\t\tif statusText != \"\" {\n\t\t\treturn nil, fmt.Errorf(\"unexpected status code: %d (%s)\", resp.StatusCode, statusText)\n\t\t}\n\t\treturn nil, fmt.Errorf(\"unexpected status code: %d\", resp.StatusCode)\n\t}\n\n\tvar data any\n\tif err = json.Unmarshal(body, &data); err != nil {\n\t\t// if unable to unmarshal data, return result as string.\n\t\treturn string(body), nil\n\t}\n\treturn data, nil\n}\n\nfunc truncateForLog(body []byte, limit int) string {\n\tif limit <= 0 || len(body) == 0 {\n\t\treturn \"\"\n\t}\n\tif len(body) <= limit {\n\t\treturn string(body)","sourceCodeStart":212,"sourceCodeEnd":248,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/http/http.go#L212-L248","documentation":"Error \"unexpected status code: %d (%s)\" thrown in googleapis/mcp-toolbox.","triggerScenarios":"Thrown at internal/sources/http/http.go:230 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}