forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uaa_gateway.go
30 lines (23 loc) · 809 Bytes
/
uaa_gateway.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package net
import (
"encoding/json"
"github.com/cloudfoundry/cli/cf/configuration/coreconfig"
"github.com/cloudfoundry/cli/cf/errors"
"github.com/cloudfoundry/cli/cf/terminal"
"github.com/cloudfoundry/cli/cf/trace"
)
type uaaErrorResponse struct {
Code string `json:"error"`
Description string `json:"error_description"`
}
var uaaErrorHandler = func(statusCode int, body []byte) error {
response := uaaErrorResponse{}
_ = json.Unmarshal(body, &response)
if response.Code == "invalid_token" {
return errors.NewInvalidTokenError(response.Description)
}
return errors.NewHTTPError(statusCode, response.Code, response.Description)
}
func NewUAAGateway(config coreconfig.Reader, ui terminal.UI, logger trace.Printer) Gateway {
return newGateway(uaaErrorHandler, config, ui, logger)
}