当前位置: 首页>>代码示例>>Golang>>正文


Golang errors.NewHttpError函数代码示例

本文整理汇总了Golang中github.com/cloudfoundry/cli/cf/errors.NewHttpError函数的典型用法代码示例。如果您正苦于以下问题:Golang NewHttpError函数的具体用法?Golang NewHttpError怎么用?Golang NewHttpError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewHttpError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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:cloudfoundry-incubator,项目名称:Diego-Enabler,代码行数:9,代码来源:routing_api_gateway.go

示例2: GetInstances

func (repo *FakeAppInstancesRepo) GetInstances(appGuid string) (instances []models.AppInstanceFields, apiErr error) {
	repo.GetInstancesAppGuid = appGuid

	if len(repo.GetInstancesResponses) > 0 {
		instances = repo.GetInstancesResponses[0]

		if len(repo.GetInstancesResponses) > 1 {
			repo.GetInstancesResponses = repo.GetInstancesResponses[1:]
		}
	}

	if len(repo.GetInstancesErrorCodes) > 0 {
		errorCode := repo.GetInstancesErrorCodes[0]

		// don't slice away the last one if this is all we have
		if len(repo.GetInstancesErrorCodes) > 1 {
			repo.GetInstancesErrorCodes = repo.GetInstancesErrorCodes[1:]
		}

		if errorCode != "" {
			apiErr = errors.NewHttpError(400, errorCode, "Error staging app")
		}
	}

	return
}
开发者ID:Jack1996,项目名称:cli,代码行数:26,代码来源:fake_app_instances_repo.go

示例3: Create

func (repo *FakeOrgRepository) Create(name string) (apiErr error) {
	if repo.CreateOrgExists {
		apiErr = errors.NewHttpError(400, errors.ORG_EXISTS, "Space already exists")
		return
	}
	repo.CreateName = name
	return
}
开发者ID:GABONIA,项目名称:cli,代码行数:8,代码来源:fake_org_repo.go

示例4: Create

func (repo *FakeBuildpackRepository) Create(name string, position *int, enabled *bool, locked *bool) (createdBuildpack models.Buildpack, apiErr error) {
	if repo.CreateBuildpackExists {
		return repo.CreateBuildpack, errors.NewHttpError(400, errors.BUILDPACK_EXISTS, "Buildpack already exists")
	}

	repo.CreateBuildpack = models.Buildpack{Name: name, Position: position, Enabled: enabled, Locked: locked}
	return repo.CreateBuildpack, repo.CreateApiResponse
}
开发者ID:Jack1996,项目名称:cli,代码行数:8,代码来源:fake_buildpack_repo.go

示例5: Create

func (repo *FakeServiceBindingRepo) Create(instanceGuid, appGuid string) (apiErr error) {
	repo.CreateServiceInstanceGuid = instanceGuid
	repo.CreateApplicationGuid = appGuid

	if repo.CreateErrorCode != "" {
		apiErr = errors.NewHttpError(400, repo.CreateErrorCode, "Error binding service")
	}

	return
}
开发者ID:GABONIA,项目名称:cli,代码行数:10,代码来源:fake_service_binding_repo.go

示例6: Create

func (repo *FakeSpaceRepository) Create(name string, orgGuid string) (space models.Space, apiErr error) {
	if repo.CreateSpaceExists {
		apiErr = errors.NewHttpError(400, errors.SPACE_EXISTS, "Space already exists")
		return
	}
	repo.CreateSpaceName = name
	repo.CreateSpaceOrgGuid = orgGuid
	space = repo.CreateSpaceSpace
	return
}
开发者ID:GABONIA,项目名称:cli,代码行数:10,代码来源:fake_space_repo.go

示例7: UpdatePassword

func (repo *FakePasswordRepo) 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:BlueSpice,项目名称:cli,代码行数:10,代码来源:fake_pwd_repo.go

示例8: GetSummary

func (repo *FakeAppSummaryRepo) 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:GABONIA,项目名称:cli,代码行数:10,代码来源:fake_app_summary_repo.go

示例9: cloudControllerErrorHandler

func cloudControllerErrorHandler(statusCode int, body []byte) error {
	response := ccErrorResponse{}
	json.Unmarshal(body, &response)

	if response.Code == 1000 { // MAGICKAL NUMBERS AHOY
		return errors.NewInvalidTokenError(response.Description)
	} else {
		return errors.NewHttpError(statusCode, strconv.Itoa(response.Code), response.Description)
	}
}
开发者ID:BlueSpice,项目名称:cli,代码行数:10,代码来源:cloud_controller_gateway.go

示例10: Create

func (repo *FakeUserRepository) Create(username, password string) (apiErr error) {
	repo.CreateUserUsername = username
	repo.CreateUserPassword = password

	if repo.CreateUserReturnsHttpError {
		apiErr = errors.NewHttpError(403, "403", "Forbidden")
	}
	if repo.CreateUserExists {
		apiErr = errors.NewModelAlreadyExistsError("User", username)
	}

	return
}
开发者ID:ArthurHlt,项目名称:cloudfoundry-cli,代码行数:13,代码来源:fake_user_repo.go

示例11: Create

func (repo *FakeServiceBindingRepo) 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:vframbach,项目名称:cli,代码行数:16,代码来源:fake_service_binding_repo.go

示例12: GetInstances

func (repo *FakeAppInstancesRepo) GetInstances(appGuid string) (instances []models.AppInstanceFields, apiErr error) {
	repo.GetInstancesAppGuid = appGuid
	time.Sleep(1 * time.Millisecond) //needed for Windows only, otherwise it thinks error codes are not assigned

	if len(repo.GetInstancesResponses) > 0 {
		instances = repo.GetInstancesResponses[0]
		repo.GetInstancesResponses = repo.GetInstancesResponses[1:]
	}

	if len(repo.GetInstancesErrorCodes) > 0 {
		errorCode := repo.GetInstancesErrorCodes[0]
		repo.GetInstancesErrorCodes = repo.GetInstancesErrorCodes[1:]
		if errorCode != "" {
			apiErr = errors.NewHttpError(400, errorCode, "Error staging app")
		}
	}

	return
}
开发者ID:palakmathur,项目名称:cli,代码行数:19,代码来源:fake_app_instances_repo.go

示例13: getAuthToken

func (uaa UAAAuthenticationRepository) 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 errors.NewWithError(T("Failed to start oauth request"), err)
	}
	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 errors.NewWithError(T("auth request failed"), err)
	}

	// 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:tools-alexuser01,项目名称:cli,代码行数:43,代码来源:authentication.go

示例14:

				[]string{"instances: 1/1"},
				[]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.APP_STOPPED, "error"))
			})

			It("prints appropriate output", func() {
				cmd.Execute(flagContext)
				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:vframbach,项目名称:cli,代码行数:31,代码来源:app_test.go

示例15:

					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.ROUTE_ALREADY_BOUND_TO_SAME_SERVICE, "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:sunatthegilddotcom,项目名称:cli,代码行数:30,代码来源:bind_route_service_test.go


注:本文中的github.com/cloudfoundry/cli/cf/errors.NewHttpError函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。