Skip to content

Commit d4d2a67

Browse files
committed
fix(client): Client won't crash on no response + no error code.
1 parent bbd8331 commit d4d2a67

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

v2/api/client.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ func (c *Client) sendRequest(request *request) (*http.Response, error) {
202202
resp, respErr := c.httpClient.Do(req)
203203

204204
// check if context deadline exceeded
205-
if respErr != nil && strings.Contains(respErr.Error(), "context deadline exceeded") || http.StatusRequestTimeout == resp.StatusCode {
205+
if respErr != nil && strings.Contains(respErr.Error(), "context deadline exceeded") || (resp != nil && http.StatusRequestTimeout == resp.StatusCode) {
206206
// retry until max retries reached
207207
sleepDuration := time.Duration(1) * time.Second
208208
for i := 0; i < MAX_CONTEXT_DEADLINE_RETRIES; i++ {
@@ -226,6 +226,10 @@ func (c *Client) sendRequest(request *request) (*http.Response, error) {
226226
resp = resp2
227227
break
228228
}
229+
respErr = respErr2
230+
}
231+
if resp == nil {
232+
return nil, fmt.Errorf("no response from Keyfactor Command after %d retries", MAX_CONTEXT_DEADLINE_RETRIES)
229233
}
230234
} else if respErr != nil {
231235
return nil, respErr

0 commit comments

Comments
 (0)