{"record":{"id":"c928fffd025cf154","repo":"googleapis/mcp-toolbox","slug":"unexpected-status-code-d","errorCode":null,"errorMessage":"unexpected status code: %d","messagePattern":"unexpected status code: (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/http/http.go","lineNumber":232,"sourceCode":"\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)\n\t}\n\treturn fmt.Sprintf(\"%s...(%d bytes truncated)\", string(body[:limit]), len(body)-limit)","sourceCodeStart":214,"sourceCodeEnd":250,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/http/http.go#L214-L250","documentation":"Error \"unexpected status code: %d\" thrown in googleapis/mcp-toolbox.","triggerScenarios":"Thrown at internal/sources/http/http.go:232 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"}