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