Skip to content

Commit

Permalink
Enhance error handling (#1674)
Browse files Browse the repository at this point in the history
  • Loading branch information
KsaweryZietara authored Jan 24, 2025
1 parent ae1078c commit 5cd54e2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions internal/broker/instance_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,12 @@ func (b *ProvisionEndpoint) validateAndExtract(details domain.ProvisionDetails,

if parameters.AdditionalWorkerNodePools != nil {
if !supportsAdditionalWorkerNodePools(details.PlanID) {
return ersContext, parameters, fmt.Errorf("additional worker node pools are not supported for plan ID: %s", details.PlanID)
message := fmt.Sprintf("additional worker node pools are not supported for plan ID: %s", details.PlanID)
return ersContext, parameters, apiresponses.NewFailureResponse(fmt.Errorf(message), http.StatusUnprocessableEntity, message)
}
if !AreNamesUnique(parameters.AdditionalWorkerNodePools) {
return ersContext, parameters, fmt.Errorf("names of additional worker node pools must be unique")
message := "names of additional worker node pools must be unique"
return ersContext, parameters, apiresponses.NewFailureResponse(fmt.Errorf(message), http.StatusUnprocessableEntity, message)
}
for _, additionalWorkerNodePool := range parameters.AdditionalWorkerNodePools {
if err := additionalWorkerNodePool.Validate(); err != nil {
Expand Down
6 changes: 4 additions & 2 deletions internal/broker/instance_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,12 @@ func (b *UpdateEndpoint) processUpdateParameters(instance *internal.Instance, de

if params.AdditionalWorkerNodePools != nil {
if !supportsAdditionalWorkerNodePools(details.PlanID) {
return domain.UpdateServiceSpec{}, fmt.Errorf("additional worker node pools are not supported for plan ID: %s", details.PlanID)
message := fmt.Sprintf("additional worker node pools are not supported for plan ID: %s", details.PlanID)
return domain.UpdateServiceSpec{}, apiresponses.NewFailureResponse(fmt.Errorf(message), http.StatusBadRequest, message)
}
if !AreNamesUnique(params.AdditionalWorkerNodePools) {
return domain.UpdateServiceSpec{}, fmt.Errorf("names of additional worker node pools must be unique")
message := "names of additional worker node pools must be unique"
return domain.UpdateServiceSpec{}, apiresponses.NewFailureResponse(fmt.Errorf(message), http.StatusBadRequest, message)
}
for _, additionalWorkerNodePool := range params.AdditionalWorkerNodePools {
if err := additionalWorkerNodePool.Validate(); err != nil {
Expand Down

0 comments on commit 5cd54e2

Please sign in to comment.