{"record":{"id":"f663222555aad00b","repo":"googleapis/mcp-toolbox","slug":"request-failed-with-status-s-s","errorCode":null,"errorMessage":"request failed with status %s: %s","messagePattern":"request failed with status (.+?): (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/databaseinsights/databaseinsights.go","lineNumber":385,"sourceCode":"\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to marshal request: %w\", err)\n\t}\n\n\thttpReq, err := http.NewRequestWithContext(ctx, \"POST\", url, bytes.NewBuffer(bodyBytes))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create http request: %w\", err)\n\t}\n\thttpReq.Header.Set(\"Content-Type\", \"application/json\")\n\n\tresp, err := s.httpClient.Do(httpReq)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to execute request: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\n\tif resp.StatusCode != http.StatusOK {\n\t\trespBody, _ := io.ReadAll(resp.Body)\n\t\treturn nil, fmt.Errorf(\"request failed with status %s: %s\", resp.Status, string(respBody))\n\t}\n\n\tvar fetchResp FetchQueryStatsResponse\n\tif err := json.NewDecoder(resp.Body).Decode(&fetchResp); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to decode response: %w\", err)\n\t}\n\n\treturn &fetchResp, nil\n}\n\n// FetchWaitEventStats executes the FetchWaitEventStats REST API method.\nfunc (s *Source) FetchWaitEventStats(ctx context.Context, req *FetchWaitEventStatsRequest) (*FetchWaitEventStatsResponse, error) {\n\turl := fmt.Sprintf(\"%s/v1beta/%s/waitEventStats:fetch\", s.getEndpointForParent(req.Parent), req.Parent)\n\n\tbodyBytes, err := json.Marshal(req)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to marshal request: %w\", err)\n\t}","sourceCodeStart":367,"sourceCodeEnd":403,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/databaseinsights/databaseinsights.go#L367-L403","documentation":"The Database Insights API returned a non-200 status for queryStats:fetch. The error includes the HTTP status line and the raw response body so the caller can see the API's error payload (e.g. permission denied, resource not found).","triggerScenarios":"Server responded 4xx/5xx: invalid or unauthorized parent resource, missing databaseinsights.roles/viewer permissions, nonexistent project/location, malformed request rejected by the API, or API outage (5xx).","commonSituations":"Service account lacking the required Database Insights IAM roles; typo in project ID or region in req.Parent; API not enabled on the project; querying an instance that doesn't exist.","solutions":["Read the response body in the error — it contains the Google API error explanation","Verify IAM permissions (e.g. roles/databaseinsights.viewer or cloudplatform scope authorization) on the parent project","Confirm the API (databaseinsights.googleapis.com) is enabled and the parent project/location/instance exist","Check req.Parent format: projects/PROJECT/locations/REGION (and any required segments)","Retry with backoff on 5xx; fix request/permissions on 4xx"],"exampleFix":"// before\nreq.Parent = \"projects/wrong-proj/locations/us-central1\" // 403/404\n// after\nreq.Parent = \"projects/my-actual-project/locations/us-central1\"","handlingStrategy":"try-catch","validationCode":"// preflight IAM check with the same credentials\ncreds, _ := google.FindDefaultCredentials(ctx, \"https://www.googleapis.com/auth/cloud-platform\")\ntok, _ := creds.TokenSource.Token()\nreq2, _ := http.NewRequestWithContext(ctx, \"GET\", \"https://databaseinsights.googleapis.com/v1beta/\"+parent, nil)\nreq2.Header.Set(\"Authorization\", \"Bearer \"+tok.AccessToken)\nresp, _ := http.DefaultClient.Do(req2)\nif resp.StatusCode != 200 { return fmt.Errorf(\"preflight failed: %s\", resp.Status) }","typeGuard":null,"tryCatchPattern":"resp, err := src.FetchQueryStats(ctx, req)\nif err != nil {\n  var apiErr struct{ Status string; Body string }\n  if strings.Contains(err.Error(), \"request failed with status\") {\n    if strings.Contains(err.Error(), \"403\") { /* fix IAM permissions */ }\n    if strings.Contains(err.Error(), \"404\") { /* verify parent resource exists */ }\n    if strings.Contains(err.Error(), \" 5\") { /* retry with backoff */ }\n  }\n  return err\n}","preventionTips":["Grant the service account Database Insights viewer roles before deployment","Enable the databaseinsights.googleapis.com API on the project","Validate project IDs and regions in configuration","Implement backoff retry for 5xx statuses"],"tags":["http","api-error","permissions","rest"],"backgroundTag":"http-non-200-response","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"}