本文整理匯總了Golang中cf/errors.NewHttpError函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewHttpError函數的具體用法?Golang NewHttpError怎麽用?Golang NewHttpError使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewHttpError函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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
}
示例2: 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
}
示例3: 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
}
示例4: cloudControllerErrorHandler
func cloudControllerErrorHandler(statusCode int, body []byte) error {
response := ccErrorResponse{}
json.Unmarshal(body, &response)
if response.Code == 1000 {
return errors.NewInvalidTokenError(response.Description)
} else {
return errors.NewHttpError(statusCode, strconv.Itoa(response.Code), response.Description)
}
}
示例5: Create
func (repo *FakeUserRepository) Create(username, password string) (apiErr error) {
repo.CreateUserUsername = username
repo.CreateUserPassword = password
if repo.CreateUserExists {
apiErr = errors.NewHttpError(400, errors.USER_EXISTS, "User already exists")
}
return
}
示例6: GetSummary
func (repo *FakeAppSummaryRepo) GetSummary(appGuid string) (summary models.AppSummary, apiErr error) {
repo.GetSummaryAppGuid = appGuid
summary = repo.GetSummarySummary
if repo.GetSummaryErrorCode != "" {
apiErr = errors.NewHttpError(400, repo.GetSummaryErrorCode, "Error")
}
return
}
示例7: UpdatePassword
func (repo *FakePasswordRepo) UpdatePassword(old string, new string) (apiErr errors.Error) {
repo.UpdateOldPassword = old
repo.UpdateNewPassword = new
if repo.UpdateUnauthorized {
apiErr = errors.NewHttpError(401, "", "", "unauthorized", "Authorization Failed")
}
return
}
示例8: 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
}
示例9: doRequestAndHandlerError
func (gateway Gateway) doRequestAndHandlerError(request *Request) (rawResponse *http.Response, apiErr errors.Error) {
rawResponse, err := gateway.doRequest(request.HttpReq)
if err != nil {
apiErr = WrapSSLErrors(request.HttpReq.URL.Host, err)
return
}
if rawResponse.StatusCode > 299 {
errorResponse := gateway.errHandler(rawResponse)
apiErr = errors.NewHttpError(rawResponse.StatusCode, errorResponse.ResponseHeader, errorResponse.ResponseBody, errorResponse.Code, errorResponse.Description)
}
return
}
示例10: Read
func (repo *FakeApplicationRepository) Read(name string) (app models.Application, apiErr error) {
repo.ReadName = name
app = repo.ReadApp
if repo.ReadErr {
apiErr = errors.New("Error finding app by name.")
}
if repo.ReadAuthErr {
apiErr = errors.NewHttpError(401, "1000", "Authentication failed.")
}
if repo.ReadNotFound {
apiErr = errors.NewModelNotFoundError("App", name)
}
return
}
示例11: 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
}
示例12: 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("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
default:
return errors.NewWithError("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
}
示例13:
{"failed"},
{"shared domains"},
{"borked!"},
})
})
It("lists only the domains for the org if the new shared_domains endpoint returns a 404", func() {
orgFields := models.OrganizationFields{
Name: "my-org",
Guid: "my-org-guid",
}
reqFactory := &testreq.FakeReqFactory{LoginSuccess: true, TargetedOrgSuccess: true, OrganizationFields: orgFields}
domainRepo := &testapi.FakeDomainRepository{
ListSharedDomainsApiResponse: errors.NewHttpError(404, "", "", "", ""),
ListDomainsForOrgDomains: []models.DomainFields{
models.DomainFields{Name: "ze-domain"},
},
}
ui := callListDomains([]string{}, reqFactory, domainRepo)
testassert.SliceContains(ui.Outputs, testassert.Lines{
{"Getting domains in org", "my-org", "my-user"},
{"ze-domain"},
})
})
It("TestListDomainsOrgDomainsFails", func() {
orgFields := models.OrganizationFields{}
orgFields.Name = "my-org"
示例14:
})
})
It("successfully pushes an app when the CC API only supports the old domains endpoints", func() {
privateDomain := models.DomainFields{
Shared: false,
Name: "private.cf-app.com",
Guid: "private-domain-guid",
}
sharedDomain := models.DomainFields{
Name: "shared.cf-app.com",
Shared: true,
Guid: "shared-domain-guid",
}
domainRepo.ListSharedDomainsApiResponse = errors.NewHttpError(404, "the-code", "something went wrong")
domainRepo.ListDomainsDomains = []models.DomainFields{privateDomain, sharedDomain}
routeRepo.FindByHostAndDomainErr = true
appRepo.ReadNotFound = true
callPush("-t", "111", "my-new-app")
Expect(routeRepo.FindByHostAndDomainHost).To(Equal("my-new-app"))
Expect(routeRepo.CreatedHost).To(Equal("my-new-app"))
Expect(routeRepo.CreatedDomainGuid).To(Equal("shared-domain-guid"))
Expect(routeRepo.BoundAppGuid).To(Equal("my-new-app-guid"))
Expect(routeRepo.BoundRouteGuid).To(Equal("my-new-app-route-guid"))
testassert.SliceContains(ui.Outputs, testassert.Lines{
{"Creating app", "my-new-app", "my-org", "my-space"},
{"OK"},
示例15:
{"failed"},
{"shared domains"},
{"borked!"},
})
})
It("lists only the domains for the org if the new shared_domains endpoint returns a 404", func() {
orgFields := models.OrganizationFields{
Name: "my-org",
Guid: "my-org-guid",
}
reqFactory := &testreq.FakeReqFactory{LoginSuccess: true, TargetedOrgSuccess: true, OrganizationFields: orgFields}
domainRepo := &testapi.FakeDomainRepository{
ListSharedDomainsApiResponse: errors.NewHttpError(404, "9003", "something bad happened"),
ListDomainsForOrgDomains: []models.DomainFields{
models.DomainFields{Name: "ze-domain"},
},
}
ui := callListDomains([]string{}, reqFactory, domainRepo)
testassert.SliceContains(ui.Outputs, testassert.Lines{
{"Getting domains in org", "my-org", "my-user"},
{"ze-domain"},
})
})
It("TestListDomainsOrgDomainsFails", func() {
orgFields := models.OrganizationFields{}
orgFields.Name = "my-org"