Sha256: a379225565d55f3e07c13a7be20792ba2b993d0ea28cd34b7826ef849db613fe

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

require 'uri'

module RestfulResourceBugsnag
  class Middleware
    def initialize(bugsnag)
      @bugsnag = bugsnag
    end

    def call(notification)
      exception = notification.exceptions.first

      if exception.is_a?(RestfulResource::HttpClient::HttpError)
        notification.add_tab(:restful_resource_response, {
          status: exception.response.status,
          body: exception.response.body,
          headers: exception.response.headers
        })
        notification.add_tab(:restful_resource_request, {
          method: exception.request.method,
          url: exception.request.url,
          accept: exception.request.accept,
          body: exception.request.body
        })
      end

      # Display the request host in the context so its easy to see in Bugsnag which service was unresponsive
      # Group the errors by host to reduce the amount of error spam
      if exception.is_a?(RestfulResource::HttpClient::ServiceUnavailable)
        notification.context = "HTTP 503: Service unavailable #{request_host_from_exception exception}"
        notification.grouping_hash = notification.context
      end

      @bugsnag.call(notification)
    end

    private

    def request_host_from_exception(exception)
      URI.parse(exception.request.url).host
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
restful_resource_bugsnag-0.1.4 lib/restful_resource_bugsnag/middleware.rb