Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add OnError hook #398

Merged
merged 7 commits into from
Jan 10, 2021
Merged

Commits on Dec 29, 2020

  1. Add OnError hook

    Adds a new hook that is called when a rest request returns an error.
    This is called when the err returned by client.execute is non-nil, and
    it is only called after all retry attempts have been exhausted.
    
    This feature is intended to support logging, metrics, tracing on request
    errors that otherwise cannot be captured with OnAfterResponse, such as
    TLS Connection errors. It also provides a way to report response errors
    only once after retries have been attempted, to avoid emitting error
    logs when a request ultimately succeeds.
    justenwalker committed Dec 29, 2020
    Configuration menu
    Copy the full SHA
    7fb9939 View commit details
    Browse the repository at this point in the history
  2. Wrap OnError errors with *ResponseError

    If a request results in an error which also has a response from the
    server, it will be wrapped with responseError so that the response is
    available to the OnError hook. The hook can use a type assertion or
    errors.As to get the response.
    
    client.OnError(func(err error) {
      if v, ok := err.(interface{ Response() *resty.Response }); ok {
        resp := v.Response()
      }
      // Log the error, increment a metric, etc...
    })
    justenwalker committed Dec 29, 2020
    Configuration menu
    Copy the full SHA
    8d9596d View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    569a226 View commit details
    Browse the repository at this point in the history

Commits on Dec 30, 2020

  1. Fix up doc comments

    justenwalker committed Dec 30, 2020
    Configuration menu
    Copy the full SHA
    cd48c32 View commit details
    Browse the repository at this point in the history
  2. Add more test coverage

    justenwalker committed Dec 30, 2020
    Configuration menu
    Copy the full SHA
    e94de3b View commit details
    Browse the repository at this point in the history

Commits on Jan 10, 2021

  1. Configuration menu
    Copy the full SHA
    d8f000d View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    56f920a View commit details
    Browse the repository at this point in the history