本文整理汇总了Golang中github.com/cloudfoundry/cli/cf/errors.NewHTTPError函数的典型用法代码示例。如果您正苦于以下问题:Golang NewHTTPError函数的具体用法?Golang NewHTTPError怎么用?Golang NewHTTPError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewHTTPError函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: errorHandler
func errorHandler(statusCode int, body []byte) error {
response := errorResponse{}
err := json.Unmarshal(body, &response)
if err != nil {
return errors.NewHTTPError(http.StatusInternalServerError, "", "")
}
return errors.NewHTTPError(statusCode, response.Name, response.Message)
}
开发者ID:Reejoshi,项目名称:cli,代码行数:9,代码来源:routing_api_gateway.go
示例2: cloudControllerErrorHandler
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)
}
开发者ID:Reejoshi,项目名称:cli,代码行数:10,代码来源:cloud_controller_gateway.go
示例3: GetSummary
func (repo *OldFakeAppSummaryRepo) GetSummary(appGUID string) (summary models.Application, apiErr error) {
repo.GetSummaryAppGUID = appGUID
summary = repo.GetSummarySummary
if repo.GetSummaryErrorCode != "" {
apiErr = errors.NewHTTPError(400, repo.GetSummaryErrorCode, "Error")
}
return
}
开发者ID:Reejoshi,项目名称:cli,代码行数:10,代码来源:old_fake_app_summary_repo.go
示例4: UpdatePassword
func (repo *OldFakePasswordRepo) UpdatePassword(old string, new string) (apiErr error) {
repo.UpdateOldPassword = old
repo.UpdateNewPassword = new
if repo.UpdateUnauthorized {
apiErr = errors.NewHTTPError(401, "unauthorized", "Authorization Failed")
}
return
}
开发者ID:Reejoshi,项目名称:cli,代码行数:10,代码来源:old_fake_password_repo.go
示例5: Create
func (repo *OldFakeServiceBindingRepo) Create(instanceGUID, appGUID string, paramsMap map[string]interface{}) (apiErr error) {
repo.CreateServiceInstanceGUID = instanceGUID
repo.CreateApplicationGUID = appGUID
repo.CreateParams = paramsMap
if repo.CreateNonHTTPErrCode != "" {
apiErr = errors.New(repo.CreateNonHTTPErrCode)
return
}
if repo.CreateErrorCode != "" {
apiErr = errors.NewHTTPError(400, repo.CreateErrorCode, "Error binding service")
}
return
}
开发者ID:yingkitw,项目名称:cli,代码行数:16,代码来源:old_fake_service_binding_repo.go
示例6: getAuthToken
func (uaa UAARepository) getAuthToken(data url.Values) error {
type uaaErrorResponse struct {
Code string `json:"error"`
Description string `json:"error_description"`
}
type AuthenticationResponse struct {
AccessToken string `json:"access_token"`
TokenType string `json:"token_type"`
RefreshToken string `json:"refresh_token"`
Error uaaErrorResponse `json:"error"`
}
path := fmt.Sprintf("%s/oauth/token", uaa.config.AuthenticationEndpoint())
request, err := uaa.gateway.NewRequest("POST", path, "Basic "+base64.StdEncoding.EncodeToString([]byte("cf:")), strings.NewReader(data.Encode()))
if err != nil {
return fmt.Errorf("%s: %s", T("Failed to start oauth request"), err.Error())
}
request.HTTPReq.Header.Set("Content-Type", "application/x-www-form-urlencoded")
response := new(AuthenticationResponse)
_, err = uaa.gateway.PerformRequestForJSONResponse(request, &response)
switch err.(type) {
case nil:
case errors.HTTPError:
return err
case *errors.InvalidTokenError:
return errors.New(T("Authentication has expired. Please log back in to re-authenticate.\n\nTIP: Use `cf login -a <endpoint> -u <user> -o <org> -s <space>` to log back in and re-authenticate."))
default:
return fmt.Errorf("%s: %s", T("auth request failed"), err.Error())
}
// TODO: get the actual status code
if response.Error.Code != "" {
return errors.NewHTTPError(0, response.Error.Code, response.Error.Description)
}
uaa.config.SetAccessToken(fmt.Sprintf("%s %s", response.TokenType, response.AccessToken))
uaa.config.SetRefreshToken(response.RefreshToken)
return nil
}
开发者ID:Reejoshi,项目名称:cli,代码行数:43,代码来源:authentication.go
示例7:
Context("when unbinding the route service succeeds", func() {
BeforeEach(func() {
routeServiceBindingRepo.UnbindReturns(nil)
})
It("says OK", func() {
Expect(runCLIErr).NotTo(HaveOccurred())
Expect(ui.Outputs()).To(ContainSubstrings(
[]string{"OK"},
))
})
})
Context("when unbinding the route service fails because it was not bound", func() {
BeforeEach(func() {
routeServiceBindingRepo.UnbindReturns(errors.NewHTTPError(http.StatusOK, errors.InvalidRelation, "http-err"))
})
It("says OK", func() {
Expect(runCLIErr).NotTo(HaveOccurred())
Expect(ui.Outputs()).To(ContainSubstrings(
[]string{"OK"},
))
})
It("warns", func() {
Expect(runCLIErr).NotTo(HaveOccurred())
Expect(ui.Outputs()).To(ContainSubstrings(
[]string{"Route", "was not bound to service instance"},
))
})
开发者ID:jasonkeene,项目名称:cli,代码行数:31,代码来源:unbind_route_service_test.go
示例8:
))
})
})
Describe("when logged in", func() {
BeforeEach(func() {
requirementsFactory.LoginSuccess = true
})
It("Sets the running environment variable group", func() {
runCommand(`{"abc":"123", "def": "456"}`)
Expect(ui.Outputs).To(ContainSubstrings(
[]string{"Setting the contents of the running environment variable group as my-user..."},
[]string{"OK"},
))
Expect(environmentVariableGroupRepo.SetRunningArgsForCall(0)).To(Equal(`{"abc":"123", "def": "456"}`))
})
It("Fails with a reasonable message when invalid JSON is passed", func() {
environmentVariableGroupRepo.SetRunningReturns(cf_errors.NewHTTPError(400, cf_errors.MessageParseError, "Request invalid due to parse error"))
runCommand(`{"abc":"123", "invalid : "json"}`)
Expect(ui.Outputs).To(ContainSubstrings(
[]string{"Setting the contents of the running environment variable group as my-user..."},
[]string{"FAILED"},
[]string{`Your JSON string syntax is invalid. Proper syntax is this: cf set-running-environment-variable-group '{"name":"value","name":"value"}'`},
))
})
})
})
开发者ID:yingkitw,项目名称:cli,代码行数:30,代码来源:set_running_environment_variable_group_test.go
示例9:
callBindService([]string{"my-app", "my-service"})
Expect(ui.Outputs()).To(ContainSubstrings(
[]string{"Binding service", "my-service", "my-app", "my-org", "my-space", "my-user"},
[]string{"OK"},
[]string{"TIP", "my-app"},
))
Expect(serviceBindingRepo.CreateCallCount()).To(Equal(1))
serviceInstanceGUID, applicationGUID, _ := serviceBindingRepo.CreateArgsForCall(0)
Expect(serviceInstanceGUID).To(Equal("my-service-guid"))
Expect(applicationGUID).To(Equal("my-app-guid"))
})
It("warns the user when the service instance is already bound to the given app", func() {
serviceBindingRepo.CreateReturns(errors.NewHTTPError(http.StatusBadRequest, errors.ServiceBindingAppServiceTaken, ""))
callBindService([]string{"my-app", "my-service"})
Expect(ui.Outputs()).To(ContainSubstrings(
[]string{"Binding service"},
[]string{"OK"},
[]string{"my-app", "is already bound", "my-service"},
))
})
It("warns the user when the error is non HTTPError ", func() {
serviceBindingRepo.CreateReturns(errors.New("1001"))
callBindService([]string{"my-app1", "my-service1"})
Expect(ui.Outputs()).To(ContainSubstrings(
[]string{"Binding service", "my-service", "my-app", "my-org", "my-space", "my-user"},
[]string{"FAILED"},
开发者ID:Reejoshi,项目名称:cli,代码行数:31,代码来源:bind_service_test.go
示例10:
Context("when the request fails", func() {
BeforeEach(func() {
flagContext.Parse("my-quota")
quotaRepo.CreateReturns(errors.New("WHOOP THERE IT IS"))
cmd.SetDependency(deps, false)
})
It("alets the user when creating the quota fails", func() {
Expect(runCLIErr).To(HaveOccurred())
Expect(ui.Outputs()).To(ContainSubstrings(
[]string{"Creating space quota", "my-quota", "my-org"},
))
Expect(runCLIErr.Error()).To(Equal("WHOOP THERE IT IS"))
})
})
Context("when the quota already exists", func() {
BeforeEach(func() {
flagContext.Parse("my-quota")
quotaRepo.CreateReturns(errors.NewHTTPError(400, errors.QuotaDefinitionNameTaken, "Quota Definition is taken: quota-sct"))
})
It("warns the user", func() {
Expect(runCLIErr).NotTo(HaveOccurred())
Expect(ui.Outputs()).ToNot(ContainSubstrings([]string{"FAILED"}))
Expect(ui.WarnOutputs).To(ContainSubstrings([]string{"already exists"}))
})
})
})
})
开发者ID:jasonkeene,项目名称:cli,代码行数:30,代码来源:create_space_quota_test.go
示例11:
Context("some sort of awful terrible error that we were not prescient enough to anticipate", func() {
BeforeEach(func() {
securityGroupRepo.CreateReturns(errors.New("Wops I failed"))
})
It("fails loudly", func() {
Expect(ui.Outputs()).To(ContainSubstrings(
[]string{"Creating security group", "my-group"},
[]string{"FAILED"},
))
})
})
Context("when the group already exists", func() {
BeforeEach(func() {
securityGroupRepo.CreateReturns(errors.NewHTTPError(400, errors.SecurityGroupNameTaken, "The security group is taken: my-group"))
})
It("warns the user when group already exists", func() {
Expect(ui.Outputs()).ToNot(ContainSubstrings([]string{"FAILED"}))
Expect(ui.WarnOutputs).To(ContainSubstrings([]string{"already exists"}))
})
})
})
})
Context("when the file specified has invalid json", func() {
BeforeEach(func() {
tempFile.Write([]byte(`[{noquote: thiswontwork}]`))
})
开发者ID:Reejoshi,项目名称:cli,代码行数:30,代码来源:create_security_group_test.go
示例12:
commandregistry.Commands.SetCommand(commandregistry.Commands.FindCommand("start").SetDependency(deps, false))
}
getInstance := func(appGUID string) ([]models.AppInstanceFields, error) {
var apiErr error
var instances []models.AppInstanceFields
if len(defaultInstanceResponses) > 0 {
instances, defaultInstanceResponses = defaultInstanceResponses[0], defaultInstanceResponses[1:]
}
if len(defaultInstanceErrorCodes) > 0 {
var errorCode string
errorCode, defaultInstanceErrorCodes = defaultInstanceErrorCodes[0], defaultInstanceErrorCodes[1:]
if errorCode != "" {
apiErr = errors.NewHTTPError(400, errorCode, "Error staging app")
}
}
return instances, apiErr
}
AfterEach(func() {
commandregistry.Register(originalAppCommand)
})
BeforeEach(func() {
deps = commandregistry.NewDependency(os.Stdout, new(tracefakes.FakePrinter))
ui = new(testterm.FakeUI)
requirementsFactory = &testreq.FakeReqFactory{}
开发者ID:yingkitw,项目名称:cli,代码行数:30,代码来源:start_test.go
示例13:
// []string{"app ports: 8080, 9090"},
[]string{"usage: 1G x 1 instances"},
[]string{"urls: fake-route-host.fake-route-domain-name"},
[]string{"last uploaded: Thu Nov 19 01:00:15 UTC 2015"},
[]string{"stack: fake-stack-name"},
// buildpack tested separately
[]string{"#0", "running", "2015-11-19 01:01:17 AM", "25.0%", "24M of 32M", "1G of 2G"},
))
})
Context("when getting the application summary fails because the app is stopped", func() {
BeforeEach(func() {
getAppSummaryModel.RunningInstances = 0
getAppSummaryModel.InstanceCount = 1
getAppSummaryModel.State = "stopped"
appSummaryRepo.GetSummaryReturns(getAppSummaryModel, errors.NewHTTPError(400, errors.InstancesError, "error"))
})
It("prints appropriate output", func() {
Expect(err).NotTo(HaveOccurred())
Expect(ui.Outputs()).To(ContainSubstrings(
[]string{"Showing health and status", "fake-app-name", "my-org", "my-space", "my-user"},
[]string{"state", "stopped"},
[]string{"instances", "0/1"},
[]string{"usage", "1G x 1 instances"},
[]string{"There are no running instances of this app."},
))
})
})
Context("when getting the application summary fails because the app has not yet finished staged", func() {
开发者ID:Reejoshi,项目名称:cli,代码行数:31,代码来源:app_test.go
示例14:
Context("when binding the route service succeeds", func() {
BeforeEach(func() {
routeServiceBindingRepo.BindReturns(nil)
})
It("says OK", func() {
Expect(ui.Outputs).To(ContainSubstrings(
[]string{"OK"},
))
})
})
Context("when binding the route service fails because it is already bound", func() {
BeforeEach(func() {
routeServiceBindingRepo.BindReturns(errors.NewHTTPError(http.StatusOK, errors.ServiceInstanceAlreadyBoundToSameRoute, "http-err"))
})
It("says OK", func() {
Expect(ui.Outputs).To(ContainSubstrings(
[]string{"OK"},
))
})
})
Context("when binding the route service fails for any other reason", func() {
BeforeEach(func() {
routeServiceBindingRepo.BindReturns(errors.New("bind-err"))
})
It("fails with the error", func() {
开发者ID:yingkitw,项目名称:cli,代码行数:30,代码来源:bind_route_service_test.go
示例15:
Path: "/v2/service_instances?accepts_incomplete=true",
Matcher: testnet.RequestBodyMatcher(`{"name":"my-service","service_plan_guid":"different-plan-guid","space_guid":"my-space-guid"}`),
Response: testnet.TestResponse{
Status: http.StatusBadRequest,
Body: `{"code":60002,"description":"The service instance name is taken: my-service"}`,
}}),
findServiceInstanceReq,
serviceOfferingReq)
})
It("fails if the plan is different", func() {
err := repo.CreateServiceInstance("my-service", "different-plan-guid", nil, nil)
Expect(testHandler).To(HaveAllRequestsCalled())
Expect(err).To(HaveOccurred())
Expect(err).To(BeAssignableToTypeOf(errors.NewHTTPError(400, "", "")))
})
})
})
Describe("UpdateServiceInstance", func() {
It("makes the right request", func() {
setupTestServer(apifakes.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "PUT",
Path: "/v2/service_instances/instance-guid?accepts_incomplete=true",
Matcher: testnet.RequestBodyMatcher(`{"service_plan_guid":"plan-guid", "tags": null}`),
Response: testnet.TestResponse{Status: http.StatusOK},
}))
err := repo.UpdateServiceInstance("instance-guid", "plan-guid", nil, nil)
Expect(testHandler).To(HaveAllRequestsCalled())
开发者ID:Reejoshi,项目名称:cli,代码行数:31,代码来源:services_test.go
示例16:
[]string{"TIP"},
))
name, orgGUID, _ := spaceRepo.CreateArgsForCall(0)
Expect(name).To(Equal("my-space"))
Expect(orgGUID).To(Equal("my-org-guid"))
userGUID, spaceGUID, orgGUID, role := userRepo.SetSpaceRoleByGUIDArgsForCall(0)
Expect(userGUID).To(Equal("my-user-guid"))
Expect(spaceGUID).To(Equal("my-space-guid"))
Expect(orgGUID).To(Equal("my-org-guid"))
Expect(role).To(Equal(models.RoleSpaceManager))
})
It("warns the user when a space with that name already exists", func() {
spaceRepo.CreateReturns(models.Space{}, errors.NewHTTPError(400, errors.SpaceNameTaken, "Space already exists"))
runCommand("my-space")
Expect(ui.Outputs()).To(ContainSubstrings(
[]string{"Creating space", "my-space"},
[]string{"OK"},
))
Expect(ui.WarnOutputs).To(ContainSubstrings([]string{"my-space", "already exists"}))
Expect(ui.Outputs()).ToNot(ContainSubstrings(
[]string{"Assigning", "my-user", "my-space", "SpaceManager"},
))
Expect(spaceRepo.CreateCallCount()).To(Equal(1))
actualSpaceName, _, _ := spaceRepo.CreateArgsForCall(0)
Expect(actualSpaceName).To(Equal("my-space"))
Expect(userRepo.SetSpaceRoleByGUIDCallCount()).To(BeZero())
开发者ID:Reejoshi,项目名称:cli,代码行数:31,代码来源:create_space_test.go
示例17:
Context("when creating the user returns an error", func() {
It("prints a warning when the given user already exists", func() {
userRepo.CreateReturns(errors.NewModelAlreadyExistsError("User", "my-user"))
runCommand("my-user", "my-password")
Expect(ui.WarnOutputs).To(ContainSubstrings(
[]string{"already exists"},
))
Expect(ui.Outputs()).ToNot(ContainSubstrings([]string{"FAILED"}))
})
It("fails when any error other than alreadyExists is returned", func() {
userRepo.CreateReturns(errors.NewHTTPError(403, "403", "Forbidden"))
runCommand("my-user", "my-password")
Expect(ui.Outputs()).To(ContainSubstrings(
[]string{"Forbidden"},
))
Expect(ui.Outputs()).To(ContainSubstrings([]string{"FAILED"}))
})
})
It("fails when no arguments are passed", func() {
Expect(runCommand()).To(BeFalse())
})
开发者ID:Reejoshi,项目名称:cli,代码行数:30,代码来源:create_user_test.go
示例18: NewUAAGateway
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)
}
开发者ID:jsloyer,项目名称:cli,代码行数:30,代码来源:uaa_gateway.go
示例19:
orgRepo.CreateReturns(nil)
requirementsFactory.LoginSuccess = true
})
It("creates an org", func() {
runCommand("my-org")
Expect(ui.Outputs).To(ContainSubstrings(
[]string{"Creating org", "my-org", "my-user"},
[]string{"OK"},
))
Expect(orgRepo.CreateArgsForCall(0).Name).To(Equal("my-org"))
})
It("fails and warns the user when the org already exists", func() {
err := errors.NewHTTPError(400, errors.OrganizationNameTaken, "org already exists")
orgRepo.CreateReturns(err)
runCommand("my-org")
Expect(ui.Outputs).To(ContainSubstrings(
[]string{"Creating org", "my-org"},
[]string{"OK"},
[]string{"my-org", "already exists"},
))
})
Context("when CC api version supports assigning orgRole by name, and feature-flag 'set_roles_by_username' is enabled", func() {
BeforeEach(func() {
config.SetAPIVersion("2.37.0")
flagRepo.FindByNameReturns(models.FeatureFlag{
Name: "set_roles_by_username",
开发者ID:yingkitw,项目名称:cli,代码行数:31,代码来源:create_org_test.go
注:本文中的github.com/cloudfoundry/cli/cf/errors.NewHTTPError函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论