Skip to content

Commit 6ba72cf

Browse files
authored
add timeout to generate service client so it does not fail (#2622)
1 parent fd5d385 commit 6ba72cf

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

backend/utils/ai.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"io"
88
"log/slog"
99
"net/http"
10+
"time"
1011
)
1112

1213
func GenerateTerraformCode(appCode string, generationEndpoint string, apiToken string) (string, error) {
@@ -38,7 +39,7 @@ func GenerateTerraformCode(appCode string, generationEndpoint string, apiToken s
3839
req.Header.Set("Authorization", "Bearer "+apiToken)
3940

4041
// Make the request
41-
client := &http.Client{}
42+
client := &http.Client{Timeout: 30 * time.Second}
4243
resp, err := client.Do(req)
4344
if err != nil {
4445
slog.Error("Error making request to code generation API", "endpoint", generationEndpoint, "error", err)
@@ -118,7 +119,7 @@ func GetAiSummaryFromTerraformPlans(plans string, summaryEndpoint string, apiTok
118119
req.Header.Set("Authorization", "Bearer "+apiToken)
119120

120121
// Make the request
121-
client := &http.Client{}
122+
client := &http.Client{Timeout: 30 * time.Second}
122123
resp, err := client.Do(req)
123124
if err != nil {
124125
slog.Error("Error making request to summary API", "endpoint", summaryEndpoint, "error", err)

0 commit comments

Comments
 (0)