@@ -94,7 +94,7 @@ func MergeTerraformObjects(old, new types.Object, attributeTypes map[string]attr
94
94
return basetypes .NewObjectValue (attributeTypes , attributes )
95
95
}
96
96
97
- // HTTPResponseDiagErr takes an HTTP response and error code and creates a Terraform Error Diagnostic if there is an error
97
+ // HTTPResponseDiagErr takes an HTTP response and error and creates a Terraform Error Diagnostic if there is an error
98
98
func HTTPResponseDiagErr (resp * http.Response , err error , errorSummary string ) diag.Diagnostics {
99
99
diags := diag.Diagnostics {}
100
100
if err != nil {
@@ -112,7 +112,19 @@ func HTTPResponseDiagErr(resp *http.Response, err error, errorSummary string) di
112
112
return diags
113
113
}
114
114
115
- // HTTPResponseDiagWarn takes an HTTP response and error code and creates a Terraform Warn Diagnostic if there is an error
115
+ // HTTPResponseDiagErrWithBody takes an HTTP status code, body, and error and creates a Terraform Error Diagnostic if there is an error
116
+ func HTTPResponseDiagErrWithBody (statusCode int , body []byte , err error , errorSummary string ) diag.Diagnostics {
117
+ diags := diag.Diagnostics {}
118
+ if err != nil {
119
+ diags .AddError (errorSummary , err .Error ())
120
+ } else if statusCode >= 300 {
121
+ details := fmt .Sprintf ("Received status code: '%v', with message: %s" , statusCode , body )
122
+ diags .AddError (errorSummary , details )
123
+ }
124
+ return diags
125
+ }
126
+
127
+ // HTTPResponseDiagWarn takes an HTTP response and error and creates a Terraform Warn Diagnostic if there is an error
116
128
// or if the status code is not in the 2xx range
117
129
func HTTPResponseDiagWarn (resp * http.Response , err error , errorSummary string ) diag.Diagnostics {
118
130
diags := diag.Diagnostics {}
@@ -131,6 +143,18 @@ func HTTPResponseDiagWarn(resp *http.Response, err error, errorSummary string) d
131
143
return diags
132
144
}
133
145
146
+ // HTTPResponseDiagWarnWithBody takes an HTTP status code, body, and error and creates a Terraform Error Diagnostic if there is an error
147
+ func HTTPResponseDiagWarnWithBody (statusCode int , body []byte , err error , errorSummary string ) diag.Diagnostics {
148
+ diags := diag.Diagnostics {}
149
+ if err != nil {
150
+ diags .AddWarning (errorSummary , err .Error ())
151
+ } else if statusCode >= 300 {
152
+ details := fmt .Sprintf ("Received status code: '%v', with message: %s" , statusCode , body )
153
+ diags .AddWarning (errorSummary , details )
154
+ }
155
+ return diags
156
+ }
157
+
134
158
// planModifierStringValueChanged is a terraform plan modifier function to use with 'RequiresReplaceIf' to check if a string value
135
159
// changed from one value to another, not including null values.
136
160
func planModifierStringValueChanged () stringplanmodifier.RequiresReplaceIfFunc {
0 commit comments