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

added error beautification for lb #306

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions ibm/flex/structures.go
Original file line number Diff line number Diff line change
Expand Up @@ -3254,24 +3254,35 @@ func FlattenSatelliteZones(zones *schema.Set) []string {

// error object
type ServiceErrorResponse struct {
Message string
StatusCode int
Result interface{}
Message string
StatusCode int
XRequestId string `json:"X-Request-Id,omitempty"`
XCorrelationId string `json:"X-Correlation-Id,omitempty"`
Result interface{}
}

func BeautifyError(err error, response *core.DetailedResponse) *ServiceErrorResponse {
var (
statusCode int
result interface{}
statusCode int
result interface{}
xRequestId string
xCorrelationId string
)
if response != nil {
statusCode = response.StatusCode
result = response.Result
}
if err != nil {
xRequestId = response.Headers["X-Request-Id"][0]
xCorrelationId = response.Headers["X-Correlation-Id"][0]
}

return &ServiceErrorResponse{
Message: err.Error(),
StatusCode: statusCode,
Result: result,
Message: err.Error(),
StatusCode: statusCode,
XRequestId: xRequestId,
XCorrelationId: xCorrelationId,
Result: result,
}
}

Expand Down
2 changes: 1 addition & 1 deletion ibm/service/vpc/resource_ibm_is_lb.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ func lbCreate(d *schema.ResourceData, meta interface{}, name, lbType, rg string,

lb, response, err := sess.CreateLoadBalancer(options)
if err != nil {
return fmt.Errorf("[ERROR] Error while creating Load Balancer err %s\n%s", err, response)
return fmt.Errorf("[ERROR] Error while creating Load Balancer err %s\n%s", flex.BeautifyError(err, response), response)
}
d.SetId(*lb.ID)
log.Printf("[INFO] Load Balancer : %s", *lb.ID)
Expand Down
Loading