hashicorp / hashicorp/go-retryablehttp
Reduce log level for errors due to context cancellation
- Dominant language
- Go
- Stars
- 2.3k
- Forks
- 298
- PR merge metrics
- No merged PRs in 30d
Description
If I make a retryable HTTP request with a context, and I cancel that context before the request is complete, [this library will log that](https://github.com/hashicorp/go-retryablehttp/blob/98169fe9787b833ec741d7fc347d76e10ee64b91/client.go#L637) at the `ERROR` log level. The resulting log looks something like:
> 2022-05-05T22:36:11.888-0400 ERROR go-retryablehttp@v0.7.1/client.go:637 request failed {"error": "Get \"https://mydomain.com\": context canceled", "method": "GET", "url": "https://mydomain.com"}
However, there are legitimate reasons to want to cancel the context and any pending HTTP requests as part of "normal operation". For example, if I'm making this HTTP request in response to a different HTTP request I received, and that different request was cancelled, I would want to cancel _this_ HTTP request since it's no longer needed. In such a case, the fact that this request gets cancelled should not be considered an "error".
It would be quite helpful for log hygiene if the code could do an `errors.Is(err, context.Cancel)` check and, if it returns true, log this at a `DEBUG` or `INFO` level instead of at the `ERROR` level.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.