Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HCPE-929: bubble up network, resource-manager, operation service errors #7

Merged
merged 8 commits into from
Feb 23, 2021

Conversation

bcmdarroch
Copy link
Contributor

🛠️ Description

This PR regenerates the network, resource-manager, and operation service SDKs from swagger that was regenerated using grpc-gateway v1.15. This version of grpc-gateway contains this fix, which adds a default error response to each endpoint.

Due to another change that added a service prefix to each endpoint to ensure uniqueness (an OpenAPI requirement), all of the file names were changed.

🏞 Background

Currently, all the service swagger files lack a default error object. This means go-swagger can't generate an error handling function, and so the service client can only return the status code and this unhelpful message:

Error: unable to get HVN (network1): response status code does not match any response statuses defined for this endpoint in the swagger spec (status 404): {}

With this change, go-swagger will generate error handlers from the default error response in the swagger. Specifically, we get this block:

/*NetworkServiceCreateDefault handles this case with default header values.

An unexpected error response.
*/
type NetworkServiceCreateDefault struct {
	_statusCode int

	Payload *models.GrpcGatewayRuntimeError
}

// Code gets the status code for the network service create default response
func (o *NetworkServiceCreateDefault) Code() int {
	return o._statusCode
}

func (o *NetworkServiceCreateDefault) Error() string {
	return fmt.Sprintf("[POST /network/2020-09-07/organizations/{network.location.organization_id}/projects/{network.location.project_id}/networks][%d] NetworkService_Create default  %+v", o._statusCode, o.Payload)
}

func (o *NetworkServiceCreateDefault) GetPayload() *models.GrpcGatewayRuntimeError {
	return o.Payload
}

func (o *NetworkServiceCreateDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {

	o.Payload = new(models.GrpcGatewayRuntimeError)

	// response payload
	if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
		return err
	}

	return nil
}

These handlers pass along the complete API error:

[GET /network/2020-09-07/organizations/{location.organization_id}/projects/{location.project_id}/clusters/{id}][404] NetworkService_Get default  &{Code:5 Details:[] Error:hvn not found Message:hvn not found}

🔗 External Links

Story: Expose Complete Errors

🏗️ How to Build and Test the Change

  1. With your local environment running, set the following environment variables:
export HCP_CLIENT_ID="servicePrincipalKeyClientID"
export HCP_CLIENT_SECRET="servicePrincipalKeyClientSecret"
export HCP_API_HOST="some.host.com"        (if unset, uses prod default)
export HCP_AUTH_URL="some.host.com"        (if unset, uses prod default)
  1. Update /cmd/hcp-sdk-go-client/main.go with some call that will error (like a GET for a consul cluster that doesn't exist).
getParams := network.NewNetworkServiceGetParams()
getParams.LocationOrganizationID = orgID
getParams.LocationProjectID = projID
getParams.ID := "not-found"

resp, err := networkClient.NetworkServiceGet(getParams, nil)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Response: %#v\n\n", resp.Payload)
  1. go run ./cmd/hcp-sdk-go-client. Check out that complete API error! ✨

👍 Definition of Done

  • network service errors are returned with complete details
  • resource-manager service errors are returned with complete details
  • operation service errors are returned with complete details

from swagger regenerated using grpc-gateway 1.15
to get default error response
also adds prefix to operationIDs to ensure uniqueness,
resulting in renamed files and functions
already included default error, so this just picks up an enum change
from swagger regenerated using grpc-gateway 1.15
to get default error response
also adds prefix to operationIDs to ensure uniqueness,
resulting in renamed files and functions
@bcmdarroch bcmdarroch requested a review from roaks3 February 17, 2021 19:25
@bcmdarroch bcmdarroch self-assigned this Feb 17, 2021
@bcmdarroch bcmdarroch changed the title Hcpe 929 HCPE-842: bubble up network, resource-manager, operation service errors HCPE-929: bubble up network, resource-manager, operation service errors Feb 17, 2021
Copy link
Contributor

@roaks3 roaks3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants