Skip to content

Commit

Permalink
return http response err (#477)
Browse files Browse the repository at this point in the history
  • Loading branch information
hila-krut-sysdig authored Jan 31, 2024
1 parent e474d10 commit 1e45b97
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
17 changes: 11 additions & 6 deletions sysdig/internal/client/v2/posture_zones.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,38 @@ const (

type PostureZoneInterface interface {
Base
CreateOrUpdatePostureZone(ctx context.Context, z *PostureZoneRequest) (*PostureZone, error)
CreateOrUpdatePostureZone(ctx context.Context, z *PostureZoneRequest) (*PostureZone, string, error)
GetPostureZone(ctx context.Context, id int) (*PostureZone, error)
DeletePostureZone(ctx context.Context, id int) error
}

func (client *Client) CreateOrUpdatePostureZone(ctx context.Context, r *PostureZoneRequest) (*PostureZone, error) {
func (client *Client) CreateOrUpdatePostureZone(ctx context.Context, r *PostureZoneRequest) (*PostureZone, string, error) {
if r.ID == "" {
r.ID = "0"
}

payload, err := Marshal(r)
if err != nil {
return nil, err
return nil, "", err
}

response, err := client.requester.Request(ctx, http.MethodPost, client.createZoneURL(), payload)
if err != nil {
return nil, err
return nil, "", err
}
defer response.Body.Close()

if response.StatusCode != http.StatusOK && response.StatusCode != http.StatusCreated && response.StatusCode != http.StatusAccepted {
errStatus, err := client.ErrorAndStatusFromResponse(response)
return nil, errStatus, err
}

wrapper, err := Unmarshal[PostureZoneResponse](response.Body)
if err != nil {
return nil, err
return nil, "", err
}

return &wrapper.Data, nil
return &wrapper.Data, "", nil
}

func (client *Client) GetPostureZone(ctx context.Context, id int) (*PostureZone, error) {
Expand Down
4 changes: 2 additions & 2 deletions sysdig/resource_sysdig_secure_posture_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ func resourceCreateOrUpdatePostureZone(ctx context.Context, d *schema.ResourceDa
return diag.FromErr(err)
}

zone, err := zoneClient.CreateOrUpdatePostureZone(ctx, req)
zone, errStatus, err := zoneClient.CreateOrUpdatePostureZone(ctx, req)
if err != nil {
return diag.FromErr(err)
return diag.Errorf("Error creating resource: %s %s", errStatus, err)
}

d.SetId(zone.ID)
Expand Down

0 comments on commit 1e45b97

Please sign in to comment.