github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/cf/net/routing_api_gateway.go (about) 1 package net 2 3 import ( 4 "encoding/json" 5 "net/http" 6 "time" 7 8 "code.cloudfoundry.org/cli/cf/configuration/coreconfig" 9 "code.cloudfoundry.org/cli/cf/errors" 10 "code.cloudfoundry.org/cli/cf/terminal" 11 "code.cloudfoundry.org/cli/cf/trace" 12 ) 13 14 type errorResponse struct { 15 Name string 16 Message string 17 } 18 19 func errorHandler(statusCode int, body []byte) error { 20 response := errorResponse{} 21 err := json.Unmarshal(body, &response) 22 if err != nil { 23 return errors.NewHTTPError(http.StatusInternalServerError, "", "") 24 } 25 26 return errors.NewHTTPError(statusCode, response.Name, response.Message) 27 } 28 29 func NewRoutingAPIGateway(config coreconfig.Reader, clock func() time.Time, ui terminal.UI, logger trace.Printer, envDialTimeout string) Gateway { 30 return Gateway{ 31 errHandler: errorHandler, 32 config: config, 33 PollingThrottle: DefaultPollingThrottle, 34 warnings: &[]string{}, 35 Clock: clock, 36 ui: ui, 37 logger: logger, 38 PollingEnabled: true, 39 DialTimeout: dialTimeout(envDialTimeout), 40 } 41 }