Skip to content

Commit

Permalink
datasource/http: don't error on 2xx code
Browse files Browse the repository at this point in the history
When a server returns a code that is not 200, we error in the current
state.

This is not conformant to the HTTP norm, as anything in the 2xx range is
considered a success, so the datasource should not error in this case.

Therefore, this commit fixes the condition in which we report an error,
so that anything in the 2xx range is now considered a success by the
datasource.
  • Loading branch information
lbajolet-hashicorp committed May 21, 2024
1 parent 493ddb1 commit 5d43239
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion datasource/http/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (d *Datasource) Execute() (cty.Value, error) {

defer resp.Body.Close()

if resp.StatusCode != 200 {
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return cty.NullVal(cty.EmptyObject), fmt.Errorf("HTTP request error. Response code: %d", resp.StatusCode)
}

Expand Down

0 comments on commit 5d43239

Please sign in to comment.