Class: ErrorInbox::Notifier

Inherits:
Object
  • Object
show all
Defined in:
lib/error_inbox/notifier.rb

Constant Summary collapse

HTTP_ERRORS =
[
  Timeout::Error,
  Errno::EINVAL,
  Errno::ECONNRESET,
  EOFError,
  Net::HTTPBadResponse,
  Net::HTTPHeaderSyntaxError,
  Net::ProtocolError,
  Errno::ECONNREFUSED,
  OpenSSL::SSL::SSLError
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Notifier

Returns a new instance of Notifier.



18
19
20
# File 'lib/error_inbox/notifier.rb', line 18

def initialize(options)
  @options = options.dup
end

Instance Method Details

#save(ex) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/error_inbox/notifier.rb', line 22

def save(ex)
  if configuration.username && configuration.password
    if ignored?(ex)
      configuration.logger.info("#{ex.class.name}: ignored")
      return {}
    end

    response = begin
      http_request(prepare_body(ex))
    rescue *HTTP_ERRORS => ex
      configuration.logger.error("#{ex.class.name}: #{ex.message}")
      nil
    end

    case response
    when Net::HTTPCreated
      JSON.load(response.body)["id"]
    else
      configuration.logger.error(response.class.name)
      {}
    end
  else
    configuration.logger.error("Missing credentials configuration")
    {}
  end
end