Skip to content

Commit 02cff14

Browse files
authored
[core]: proper ParseResponse handling
1 parent 1737ff4 commit 02cff14

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

openstack/networking/v2/extensions/fwaas_v2/groups/requests.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
6969

7070
// Get retrieves a particular firewall group based on its unique ID.
7171
func Get(ctx context.Context, c *gophercloud.ServiceClient, id string) (r GetResult) {
72-
_, r.Err = c.Get(ctx, resourceURL(c, id), &r.Body, nil)
72+
resp, err := c.Get(ctx, resourceURL(c, id), &r.Body, nil)
73+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
7374
return
7475
}
7576

@@ -107,7 +108,8 @@ func Create(ctx context.Context, c *gophercloud.ServiceClient, opts CreateOptsBu
107108
r.Err = err
108109
return
109110
}
110-
_, r.Err = c.Post(ctx, rootURL(c), b, &r.Body, nil)
111+
resp, err := c.Post(ctx, rootURL(c), b, &r.Body, nil)
112+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
111113
return
112114
}
113115

@@ -142,9 +144,10 @@ func Update(ctx context.Context, c *gophercloud.ServiceClient, id string, opts U
142144
r.Err = err
143145
return
144146
}
145-
_, r.Err = c.Put(ctx, resourceURL(c, id), b, &r.Body, &gophercloud.RequestOpts{
147+
resp, err := c.Put(ctx, resourceURL(c, id), b, &r.Body, &gophercloud.RequestOpts{
146148
OkCodes: []int{200},
147149
})
150+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
148151
return
149152
}
150153

@@ -165,9 +168,10 @@ func RemoveIngressPolicy(ctx context.Context, c *gophercloud.ServiceClient, id s
165168
r.Err = err
166169
return
167170
}
168-
_, r.Err = c.Put(ctx, resourceURL(c, id), b, &r.Body, &gophercloud.RequestOpts{
171+
resp, err := c.Put(ctx, resourceURL(c, id), b, &r.Body, &gophercloud.RequestOpts{
169172
OkCodes: []int{200},
170173
})
174+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
171175
return
172176
}
173177

@@ -181,14 +185,16 @@ func RemoveEgressPolicy(ctx context.Context, c *gophercloud.ServiceClient, id st
181185
r.Err = err
182186
return
183187
}
184-
_, r.Err = c.Put(ctx, resourceURL(c, id), b, &r.Body, &gophercloud.RequestOpts{
188+
resp, err := c.Put(ctx, resourceURL(c, id), b, &r.Body, &gophercloud.RequestOpts{
185189
OkCodes: []int{200},
186190
})
191+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
187192
return
188193
}
189194

190195
// Delete will permanently delete a particular firewall group based on its unique ID.
191196
func Delete(ctx context.Context, c *gophercloud.ServiceClient, id string) (r DeleteResult) {
192-
_, r.Err = c.Delete(ctx, resourceURL(c, id), nil)
197+
resp, err := c.Delete(ctx, resourceURL(c, id), nil)
198+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
193199
return
194200
}

openstack/networking/v2/extensions/fwaas_v2/policies/requests.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,15 @@ func Create(ctx context.Context, c *gophercloud.ServiceClient, opts CreateOptsBu
9191
r.Err = err
9292
return
9393
}
94-
_, r.Err = c.Post(ctx, rootURL(c), b, &r.Body, nil)
94+
resp, err := c.Post(ctx, rootURL(c), b, &r.Body, nil)
95+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
9596
return
9697
}
9798

9899
// Get retrieves a particular firewall policy based on its unique ID.
99100
func Get(ctx context.Context, c *gophercloud.ServiceClient, id string) (r GetResult) {
100-
_, r.Err = c.Get(ctx, resourceURL(c, id), &r.Body, nil)
101+
resp, err := c.Get(ctx, resourceURL(c, id), &r.Body, nil)
102+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
101103
return
102104
}
103105

@@ -130,15 +132,17 @@ func Update(ctx context.Context, c *gophercloud.ServiceClient, id string, opts U
130132
r.Err = err
131133
return
132134
}
133-
_, r.Err = c.Put(ctx, resourceURL(c, id), b, &r.Body, &gophercloud.RequestOpts{
135+
resp, err := c.Put(ctx, resourceURL(c, id), b, &r.Body, &gophercloud.RequestOpts{
134136
OkCodes: []int{200},
135137
})
138+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
136139
return
137140
}
138141

139142
// Delete will permanently delete a particular firewall policy based on its unique ID.
140143
func Delete(ctx context.Context, c *gophercloud.ServiceClient, id string) (r DeleteResult) {
141-
_, r.Err = c.Delete(ctx, resourceURL(c, id), nil)
144+
resp, err := c.Delete(ctx, resourceURL(c, id), nil)
145+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
142146
return
143147
}
144148

@@ -162,16 +166,18 @@ func InsertRule(ctx context.Context, c *gophercloud.ServiceClient, id string, op
162166
r.Err = err
163167
return
164168
}
165-
_, r.Err = c.Put(ctx, insertURL(c, id), b, &r.Body, &gophercloud.RequestOpts{
169+
resp, err := c.Put(ctx, insertURL(c, id), b, &r.Body, &gophercloud.RequestOpts{
166170
OkCodes: []int{200},
167171
})
172+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
168173
return
169174
}
170175

171176
func RemoveRule(ctx context.Context, c *gophercloud.ServiceClient, id, ruleID string) (r RemoveRuleResult) {
172177
b := map[string]any{"firewall_rule_id": ruleID}
173-
_, r.Err = c.Put(ctx, removeURL(c, id), b, &r.Body, &gophercloud.RequestOpts{
178+
resp, err := c.Put(ctx, removeURL(c, id), b, &r.Body, &gophercloud.RequestOpts{
174179
OkCodes: []int{200},
175180
})
181+
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
176182
return
177183
}

0 commit comments

Comments
 (0)