MCPcopy
hub / github.com/cloudflare/cloudflared / statusCodeToError

Method statusCodeToError

cfapi/base_client.go:221–243  ·  view source on GitHub ↗
(op string, resp *http.Response)

Source from the content-addressed store, hash-verified

219}
220
221func (r *RESTClient) statusCodeToError(op string, resp *http.Response) error {
222 if resp.Header.Get("Content-Type") == "application/json" {
223 var errorsResp response
224 if json.NewDecoder(resp.Body).Decode(&errorsResp) == nil {
225 if err := errorsResp.checkErrors(); err != nil {
226 return errors.Errorf("Failed to %s: %s", op, err)
227 }
228 }
229 }
230
231 switch resp.StatusCode {
232 case http.StatusOK:
233 return nil
234 case http.StatusBadRequest:
235 return ErrBadRequest
236 case http.StatusUnauthorized, http.StatusForbidden:
237 return ErrUnauthorized
238 case http.StatusNotFound:
239 return ErrNotFound
240 }
241 return errors.Errorf("API call to %s failed with status %d: %s", op,
242 resp.StatusCode, http.StatusText(resp.StatusCode))
243}

Callers 15

RouteTunnelMethod · 0.95
CreateVirtualNetworkMethod · 0.95
ListVirtualNetworksMethod · 0.95
DeleteVirtualNetworkMethod · 0.95
UpdateVirtualNetworkMethod · 0.95
ListRoutesMethod · 0.95
AddRouteMethod · 0.95
DeleteRouteMethod · 0.95
GetByIPMethod · 0.95
CreateTunnelMethod · 0.95
GetTunnelMethod · 0.95
GetTunnelTokenMethod · 0.95

Calls 4

checkErrorsMethod · 0.95
GetMethod · 0.80
ErrorfMethod · 0.80
DecodeMethod · 0.45

Tested by

no test coverage detected