Skip to content

Commit 42a1e9a

Browse files
Better Postman API request timeout logging (#4186)
This should give us some more visibility into when this happens
1 parent 3365171 commit 42a1e9a

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

pkg/sources/postman/postman_client.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package postman
22

33
import (
44
"encoding/json"
5+
"errors"
56
"fmt"
67
"io"
78
"net/http"
9+
"net/url"
810
"strconv"
911
"time"
1012

@@ -259,13 +261,21 @@ func checkResponseStatus(r *http.Response) error {
259261

260262
// getPostmanResponseBodyBytes makes a request to the Postman API and returns the response body as bytes.
261263
func (c *Client) getPostmanResponseBodyBytes(ctx trContext.Context, urlString string, headers map[string]string) ([]byte, error) {
264+
ctx = trContext.WithValues(ctx, "url", urlString)
265+
262266
req, err := c.NewRequest(urlString, headers)
263267
if err != nil {
264268
return nil, err
265269
}
266270

267271
resp, err := c.HTTPClient.Do(req)
268272
if err != nil {
273+
// HTTPClient.Do returns a err which will always be a url.Error
274+
// see docs: https://pkg.go.dev/net/http#Client.Do
275+
var urlErr *url.Error
276+
if errors.As(err, &urlErr) && urlErr.Timeout() {
277+
ctx.Logger().Error(urlErr, "postman API timed out. Are we requesting an especially large item from the Postman API?")
278+
}
269279
return nil, err
270280
}
271281
defer resp.Body.Close()

0 commit comments

Comments
 (0)