Skip to content

Commit 1e45b97

Browse files
return http response err (#477)
1 parent e474d10 commit 1e45b97

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

sysdig/internal/client/v2/posture_zones.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,38 @@ const (
1313

1414
type PostureZoneInterface interface {
1515
Base
16-
CreateOrUpdatePostureZone(ctx context.Context, z *PostureZoneRequest) (*PostureZone, error)
16+
CreateOrUpdatePostureZone(ctx context.Context, z *PostureZoneRequest) (*PostureZone, string, error)
1717
GetPostureZone(ctx context.Context, id int) (*PostureZone, error)
1818
DeletePostureZone(ctx context.Context, id int) error
1919
}
2020

21-
func (client *Client) CreateOrUpdatePostureZone(ctx context.Context, r *PostureZoneRequest) (*PostureZone, error) {
21+
func (client *Client) CreateOrUpdatePostureZone(ctx context.Context, r *PostureZoneRequest) (*PostureZone, string, error) {
2222
if r.ID == "" {
2323
r.ID = "0"
2424
}
2525

2626
payload, err := Marshal(r)
2727
if err != nil {
28-
return nil, err
28+
return nil, "", err
2929
}
3030

3131
response, err := client.requester.Request(ctx, http.MethodPost, client.createZoneURL(), payload)
3232
if err != nil {
33-
return nil, err
33+
return nil, "", err
3434
}
3535
defer response.Body.Close()
3636

37+
if response.StatusCode != http.StatusOK && response.StatusCode != http.StatusCreated && response.StatusCode != http.StatusAccepted {
38+
errStatus, err := client.ErrorAndStatusFromResponse(response)
39+
return nil, errStatus, err
40+
}
41+
3742
wrapper, err := Unmarshal[PostureZoneResponse](response.Body)
3843
if err != nil {
39-
return nil, err
44+
return nil, "", err
4045
}
4146

42-
return &wrapper.Data, nil
47+
return &wrapper.Data, "", nil
4348
}
4449

4550
func (client *Client) GetPostureZone(ctx context.Context, id int) (*PostureZone, error) {

sysdig/resource_sysdig_secure_posture_zone.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ func resourceCreateOrUpdatePostureZone(ctx context.Context, d *schema.ResourceDa
138138
return diag.FromErr(err)
139139
}
140140

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

146146
d.SetId(zone.ID)

0 commit comments

Comments
 (0)