forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloud_controller_gateway.go
37 lines (29 loc) · 951 Bytes
/
cloud_controller_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
31
32
33
34
35
36
37
package net
import (
"encoding/json"
"strconv"
"time"
"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 ccErrorResponse struct {
Code int
Description string
}
const invalidTokenCode = 1000
func cloudControllerErrorHandler(statusCode int, body []byte) error {
response := ccErrorResponse{}
json.Unmarshal(body, &response)
if response.Code == invalidTokenCode {
return errors.NewInvalidTokenError(response.Description)
}
return errors.NewHTTPError(statusCode, strconv.Itoa(response.Code), response.Description)
}
func NewCloudControllerGateway(config coreconfig.Reader, clock func() time.Time, ui terminal.UI, logger trace.Printer) Gateway {
gateway := newGateway(cloudControllerErrorHandler, config, ui, logger)
gateway.Clock = clock
gateway.PollingEnabled = true
return gateway
}