github.com/rakutentech/cli@v6.12.5-0.20151006231303-24468b65536e+incompatible/cf/net/uaa_gateway.go (about) 1 package net 2 3 import ( 4 "encoding/json" 5 6 "github.com/cloudfoundry/cli/cf/configuration/core_config" 7 "github.com/cloudfoundry/cli/cf/errors" 8 "github.com/cloudfoundry/cli/cf/terminal" 9 ) 10 11 type uaaErrorResponse struct { 12 Code string `json:"error"` 13 Description string `json:"error_description"` 14 } 15 16 var uaaErrorHandler = func(statusCode int, body []byte) error { 17 response := uaaErrorResponse{} 18 json.Unmarshal(body, &response) 19 20 if response.Code == "invalid_token" { 21 return errors.NewInvalidTokenError(response.Description) 22 } else { 23 return errors.NewHttpError(statusCode, response.Code, response.Description) 24 } 25 } 26 27 func NewUAAGateway(config core_config.Reader, ui terminal.UI) Gateway { 28 return newGateway(uaaErrorHandler, config, ui) 29 }