Skip to content

Commit

Permalink
Fix incorrect API error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
alexhung committed Jul 9, 2024
1 parent eee7ea9 commit fb4751c
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 19 deletions.
8 changes: 3 additions & 5 deletions pkg/platform/resource_global_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,7 @@ func (r *globalRoleResource) Create(ctx context.Context, req resource.CreateRequ
return
}

// Return error if the HTTP status code is not 201 Created
if response.StatusCode() != http.StatusCreated {
if response.IsError() {
utilfw.UnableToCreateResourceError(resp, response.String())
return
}
Expand Down Expand Up @@ -290,8 +289,7 @@ func (r *globalRoleResource) Update(ctx context.Context, req resource.UpdateRequ
return
}

// Return error if the HTTP status code is not 200 OK
if response.StatusCode() != http.StatusOK {
if response.IsError() {
utilfw.UnableToUpdateResourceError(resp, response.String())
return
}
Expand All @@ -316,7 +314,7 @@ func (r *globalRoleResource) Delete(ctx context.Context, req resource.DeleteRequ
return
}

if response.StatusCode() != http.StatusNoContent {
if response.IsError() {
utilfw.UnableToDeleteResourceError(resp, response.String())
return
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/platform/resource_oidc_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func (r *odicConfigurationResource) Delete(ctx context.Context, req resource.Del
return
}

if response.StatusCode() != http.StatusNoContent {
if response.IsError() {
utilfw.UnableToDeleteResourceError(resp, response.String())
return
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/platform/resource_oidc_identity_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ func (r *odicIdentityMappingResource) Delete(ctx context.Context, req resource.D
return
}

if response.StatusCode() != http.StatusNoContent {
if response.IsError() {
utilfw.UnableToDeleteResourceError(resp, response.String())
return
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/platform/resource_permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -829,8 +829,7 @@ func (r *permissionResource) Create(ctx context.Context, req resource.CreateRequ
return
}

// Return error if the HTTP status code is not 201 Created
if response.StatusCode() != http.StatusCreated {
if response.IsError() {
utilfw.UnableToCreateResourceError(resp, response.String())
return
}
Expand Down Expand Up @@ -935,7 +934,7 @@ func (r *permissionResource) Delete(ctx context.Context, req resource.DeleteRequ
return
}

if response.StatusCode() != http.StatusNoContent {
if response.IsError() {
utilfw.UnableToDeleteResourceError(resp, response.String())
return
}
Expand Down
6 changes: 2 additions & 4 deletions pkg/platform/resource_reverse_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,7 @@ func (r *reverseProxyResource) Create(ctx context.Context, req resource.CreateRe
return
}

// Return error if the HTTP status code is not 201 Created
if response.StatusCode() != http.StatusCreated {
if response.IsError() {
utilfw.UnableToCreateResourceError(resp, response.String())
return
}
Expand Down Expand Up @@ -312,8 +311,7 @@ func (r *reverseProxyResource) Update(ctx context.Context, req resource.UpdateRe
return
}

// Return error if the HTTP status code is not 201 Created
if response.StatusCode() != http.StatusCreated {
if response.IsError() {
utilfw.UnableToUpdateResourceError(resp, response.String())
return
}
Expand Down
8 changes: 3 additions & 5 deletions pkg/platform/resource_workers_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,7 @@ func (r *workersServiceResource) Create(ctx context.Context, req resource.Create
return
}

// Return error if the HTTP status code is not 201 Created
if response.StatusCode() != http.StatusCreated {
if response.IsError() {
utilfw.UnableToCreateResourceError(resp, response.String())
return
}
Expand Down Expand Up @@ -453,8 +452,7 @@ func (r *workersServiceResource) Update(ctx context.Context, req resource.Update
return
}

// Return error if the HTTP status code is not 204 No Content
if response.StatusCode() != http.StatusNoContent {
if response.IsError() {
utilfw.UnableToUpdateResourceError(resp, response.String())
return
}
Expand All @@ -481,7 +479,7 @@ func (r *workersServiceResource) Delete(ctx context.Context, req resource.Delete
return
}

if response.StatusCode() != http.StatusNoContent {
if response.IsError() {
utilfw.UnableToDeleteResourceError(resp, response.String())
return
}
Expand Down

0 comments on commit fb4751c

Please sign in to comment.