Class: Zumobi::ExceptionHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/zumobi/exception_handler.rb

Constant Summary collapse

EXCLUDED_EXCEPTIONS =

Network-related errors we’ll skip…

[
Curl::Err::ConnectionFailedError.name,
Curl::Err::GotNothingError.name,
Curl::Err::HostResolutionError.name,
Curl::Err::PartialFileError.name,
Curl::Err::RecvError.name,
Curl::Err::TimeoutError.name, 
Errno::ECONNRESET.name, 
Errno::EHOSTUNREACH.name, 
Errno::ETIMEDOUT.name, 
Net::HTTPFatalError.name, 
Net::HTTPServerException.name,
RightAws::AwsError.name, 
Timeout::Error.name ]
@@ip_address =
nil

Class Method Summary collapse

Class Method Details

.ip_addressObject



28
29
30
# File 'lib/zumobi/exception_handler.rb', line 28

def self.ip_address
    @@ip_address = @@ip_address || IPSocket.getaddress(Socket.gethostname)
end

.message(message) ⇒ Object



49
50
51
52
53
# File 'lib/zumobi/exception_handler.rb', line 49

def self.message(message)
    Rails.logger.info(message)
    Airbrake.notify(nil, {:error_message => message,
        :session => {"IP Address" => "#{ExceptionHandler.ip_address}"}})
end

.method_missing(name, *args, &block) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/zumobi/exception_handler.rb', line 32

def self.method_missing(name, *args, &block)
    if [:debug, :info, :warn, :error, :fatal].include?(name)
        e = args[0]
        unless EXCLUDED_EXCEPTIONS.include?(e.class.name)
            if (Airbrake.configuration.api_key.blank?)
                raise "To log errors, add an airbrake.rb initializer in your rails app."
            end
            # Note: Rails doesn't log the stacktrace... it's quite annoying
            backtrace = e.backtrace ? ("\n" + e.backtrace.join("\n")) : ""
            Rails.logger.send(name, e.message + backtrace, &block)

            # Send to Airbrake
            Airbrake.notify(e, {:session => {"IP Address" => "#{ExceptionHandler.ip_address}"}})
        end
    end
end