{"record":{"id":"13e8178d04a0fbbd","repo":"cloudflare/cloudflared","slug":"failed-to-s-s","errorCode":null,"errorMessage":"Failed to %s: %s","messagePattern":"Failed to (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cfapi/base_client.go","lineNumber":226,"sourceCode":"\t}\n\treturn fmt.Errorf(\"API errors: %s\", messagesBuilder.String())\n}\n\ntype apiError struct {\n\tCode    json.Number `json:\"code,omitempty\"`\n\tMessage string      `json:\"message,omitempty\"`\n}\n\nfunc (e apiError) Error() string {\n\treturn fmt.Sprintf(\"code: %v, reason: %s\", e.Code, e.Message)\n}\n\nfunc (r *RESTClient) statusCodeToError(op string, resp *http.Response) error {\n\tif resp.Header.Get(\"Content-Type\") == \"application/json\" {\n\t\tvar errorsResp response\n\t\tif json.NewDecoder(resp.Body).Decode(&errorsResp) == nil {\n\t\t\tif err := errorsResp.checkErrors(); err != nil {\n\t\t\t\treturn errors.Errorf(\"Failed to %s: %s\", op, err)\n\t\t\t}\n\t\t}\n\t}\n\n\tswitch resp.StatusCode {\n\tcase http.StatusOK:\n\t\treturn nil\n\tcase http.StatusBadRequest:\n\t\treturn ErrBadRequest\n\tcase http.StatusUnauthorized, http.StatusForbidden:\n\t\treturn ErrUnauthorized\n\tcase http.StatusNotFound:\n\t\treturn ErrNotFound\n\t}\n\treturn errors.Errorf(\"API call to %s failed with status %d: %s\", op,\n\t\tresp.StatusCode, http.StatusText(resp.StatusCode))\n}\n","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/cloudflare/cloudflared/blob/2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f/cfapi/base_client.go#L208-L244","documentation":"API-error formatting in RESTClient.statusCodeToError: the response was JSON and contained structured error entries, so the client builds a 'Failed to <op>: <combined reasons>' error instead of falling through to status-code sentinel errors (ErrBadRequest, ErrUnauthorized, etc.). It carries the Cloudflare API's own explanation of why the operation was rejected.","triggerScenarios":"Thrown at cfapi/base_client.go:226 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Read the embedded reasons from the API error payload — they state the exact rejection cause.","Fix the request (bad route CIDR, duplicate name, missing permission) per the API message.","For authorization failures, re-login (`cloudflared tunnel login`) to refresh cert.pem."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f","analyzedAt":"2026-09-06T04:14:33.757Z","contentChangedAt":"2026-09-06T04:14:33.757Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}