From 5d4323965454b68b5cca49b3cb60b1f5ab27caeb Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Tue, 21 May 2024 10:49:02 -0400 Subject: [PATCH] datasource/http: don't error on 2xx code 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. --- datasource/http/data.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datasource/http/data.go b/datasource/http/data.go index 58dec04c3..5359e0c91 100644 --- a/datasource/http/data.go +++ b/datasource/http/data.go @@ -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) }