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

refactor: check success by 2xx range #29

Merged
merged 1 commit into from
Dec 18, 2024
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v0.6.1
REFACTOR:
- Validate success responses by checking for HTTP status codes in the 2xx range

## v0.6.0

FEATURES:
Expand Down
4 changes: 2 additions & 2 deletions client/buildingblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (c *MeshStackProviderClient) ReadBuildingBlock(uuid string) (*MeshBuildingB
return nil, nil
}

if res.StatusCode != 200 {
if !isSuccessHTTPStatus(res) {
return nil, fmt.Errorf("unexpected status code: %d, %s", res.StatusCode, data)
}

Expand Down Expand Up @@ -141,7 +141,7 @@ func (c *MeshStackProviderClient) CreateBuildingBlock(bb *MeshBuildingBlockCreat
return nil, err
}

if res.StatusCode != 201 {
if !isSuccessHTTPStatus(res) {
return nil, fmt.Errorf("unexpected status code: %d, %s", res.StatusCode, data)
}

Expand Down
8 changes: 4 additions & 4 deletions client/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (c *MeshStackProviderClient) ReadProject(workspace string, name string) (*M
return nil, nil
}

if res.StatusCode != 200 {
if !isSuccessHTTPStatus(res) {
return nil, fmt.Errorf("unexpected status code: %d, %s", res.StatusCode, data)
}

Expand Down Expand Up @@ -119,7 +119,7 @@ func (c *MeshStackProviderClient) ReadProjects(workspaceIdentifier string, payme
return nil, fmt.Errorf("failed to read response body: %w", err)
}

if res.StatusCode != http.StatusOK {
if !isSuccessHTTPStatus(res) {
return nil, fmt.Errorf("unexpected status code: %d, %s", res.StatusCode, data)
}

Expand Down Expand Up @@ -178,7 +178,7 @@ func (c *MeshStackProviderClient) CreateProject(project *MeshProjectCreate) (*Me
return nil, err
}

if res.StatusCode != 201 {
if !isSuccessHTTPStatus(res) {
return nil, fmt.Errorf("unexpected status code: %d, %s", res.StatusCode, data)
}

Expand Down Expand Up @@ -219,7 +219,7 @@ func (c *MeshStackProviderClient) UpdateProject(project *MeshProjectCreate) (*Me
return nil, err
}

if res.StatusCode != 200 {
if !isSuccessHTTPStatus(res) {
return nil, fmt.Errorf("unexpected status code: %d, %s", res.StatusCode, data)
}

Expand Down
4 changes: 2 additions & 2 deletions client/project_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (c *MeshStackProviderClient) readProjectBinding(name string, contentType st
return nil, nil
}

if res.StatusCode != 200 {
if !isSuccessHTTPStatus(res) {
return nil, fmt.Errorf("unexpected status code: %d, %s", res.StatusCode, data)
}

Expand Down Expand Up @@ -120,7 +120,7 @@ func (c *MeshStackProviderClient) createProjectBinding(binding *MeshProjectBindi
return nil, err
}

if res.StatusCode != 200 {
if !isSuccessHTTPStatus(res) {
return nil, fmt.Errorf("unexpected status code: %d, %s", res.StatusCode, data)
}

Expand Down
13 changes: 13 additions & 0 deletions client/status_code_checker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package client

import (
"net/http"
)

func isSuccessHTTPStatus(resp *http.Response) bool {
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return false
}

return true
}
8 changes: 4 additions & 4 deletions client/tag_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (c *MeshStackProviderClient) ReadTagDefinitions() (*[]MeshTagDefinition, er
return nil, fmt.Errorf("failed to read response body: %w", err)
}

if res.StatusCode != http.StatusOK {
if !isSuccessHTTPStatus(res) {
return nil, fmt.Errorf("unexpected status code: %d, %s", res.StatusCode, data)
}

Expand Down Expand Up @@ -156,7 +156,7 @@ func (c *MeshStackProviderClient) ReadTagDefinition(name string) (*MeshTagDefini
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
if !isSuccessHTTPStatus(resp) {
return nil, fmt.Errorf("failed to read tag definition: %s", resp.Status)
}

Expand Down Expand Up @@ -191,7 +191,7 @@ func (c *MeshStackProviderClient) CreateTagDefinition(tagDefinition *MeshTagDefi
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusCreated {
if !isSuccessHTTPStatus(resp) {
return nil, fmt.Errorf("failed to create tag definition: %s", resp.Status)
}

Expand Down Expand Up @@ -224,7 +224,7 @@ func (c *MeshStackProviderClient) UpdateTagDefinition(tagDefinition *MeshTagDefi
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
if !isSuccessHTTPStatus(resp) {
return nil, fmt.Errorf("failed to update tag definition: %s", resp.Status)
}

Expand Down
4 changes: 2 additions & 2 deletions client/tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (c *MeshStackProviderClient) ReadTenant(workspace string, project string, p
return nil, nil
}

if res.StatusCode != 200 {
if !isSuccessHTTPStatus(res) {
return nil, fmt.Errorf("unexpected status code: %d, %s", res.StatusCode, data)
}

Expand Down Expand Up @@ -121,7 +121,7 @@ func (c *MeshStackProviderClient) CreateTenant(tenant *MeshTenantCreate) (*MeshT
return nil, err
}

if res.StatusCode != 201 {
if !isSuccessHTTPStatus(res) {
return nil, fmt.Errorf("unexpected status code: %d, %s", res.StatusCode, data)
}

Expand Down
Loading