diff options
Diffstat (limited to 'internal/http/http.go')
| -rw-r--r-- | internal/http/http.go | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/internal/http/http.go b/internal/http/http.go index 58e8f05..262309a 100644 --- a/internal/http/http.go +++ b/internal/http/http.go @@ -201,8 +201,10 @@ func (c *Client) Do(ctx context.Context, method string, urlStr string, opts *Opt // Do request res, err := c.Client.Do(req) if err != nil { - return nil, nil, errors.WrapPrefix(err, - fmt.Sprintf("failed HTTP request with method %s and url %s", method, urlStr), 0) + if errors.Is(err, context.DeadlineExceeded) { + return nil, nil, &TimeoutError{URL: urlStr, Method: method} + } + return nil, nil, fmt.Errorf("failed HTTP request with method: '%s', url: '%s' and error: %w", method, urlStr, err) } // Request successful, make sure body is closed at the end @@ -229,6 +231,21 @@ func (c *Client) Do(ctx context.Context, method string, urlStr string, opts *Opt return res.Header, body, nil } +// TimeoutError indicates that we have gotten a timeout +type TimeoutError struct { + URL string + Method string +} + +// Error returns the TimeoutError as an error string. +func (e *TimeoutError) Error() string { + return fmt.Sprintf( + "timeout in obtaining HTTP resource: '%s' with method: '%s'", + e.URL, + e.Method, + ) +} + // StatusError indicates that we have received a HTTP status error. type StatusError struct { URL string |
