Class: ExceptIO::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/exceptio/client.rb

Constant Summary collapse

VERSION =
"0.1.6"
DEFAULT_IGNORED_EXCEPTIONS =
["ActiveRecord::RecordNotFound", "ActionController::InvalidAuthenticityToken", "ActionController::RoutingError"]

Class Method Summary collapse

Class Method Details

.app_keyObject



35
36
37
# File 'lib/exceptio/client.rb', line 35

def self.app_key
  @app_key
end

.applicationObject



31
32
33
# File 'lib/exceptio/client.rb', line 31

def self.application
  @application
end

.configure(application, app_key, endpoint = 'except.io') ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/exceptio/client.rb', line 13

def self.configure(application, app_key, endpoint = 'except.io')
  @application = application
  @app_key = app_key
  @configured = true
  base_uri endpoint
  if defined?(Rails)
    if Rails.version.starts_with?("2.3")
      ActionController::Base.send(:include, ExceptIO::Hooks::Rails23)
    elsif Rails::VERSION::MAJOR >= 3
      ActionController::Base.send(:include, ExceptIO::Hooks::Rails3Plus)
    end
  end
end

.configuredObject



27
28
29
# File 'lib/exceptio/client.rb', line 27

def self.configured
  @configured
end

.handle(environment = "production", params = {}, session = {}, request_url = nil, &block) ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'lib/exceptio/client.rb', line 61

def self.handle(environment = "production", params = {}, session = {}, request_url = nil, &block)
  return unless block_given?
  begin
    yield
  rescue
    ExceptIO::Client.log($!, environment, params, session, request_url)
    nil
  end
end

.ignored_exceptionsObject



39
40
41
# File 'lib/exceptio/client.rb', line 39

def self.ignored_exceptions
  @ignored_exceptions ||= DEFAULT_IGNORED_EXCEPTIONS.clone
end

.ignored_exceptions=(ignored_exceptions) ⇒ Object



43
44
45
# File 'lib/exceptio/client.rb', line 43

def self.ignored_exceptions=(ignored_exceptions)
  @ignored_exceptions = ignored_exceptions
end

.log(exception, environment = "production", params = {}, session = {}, request_url = nil) ⇒ Object



54
55
56
57
58
59
# File 'lib/exceptio/client.rb', line 54

def self.log(exception, environment = "production", params = {}, session = {}, request_url = nil)
  return false unless self.configured
  return false if self.ignored_exceptions.map(&:to_s).include?(exception.class.name)
  res = self.post("/applications/#{self.application}/errors", {:query => {:app_key => self.app_key}, :body => {:error => {:message => exception.message, :backtrace => exception.backtrace, :type => exception.class.name, :environment => environment, :params => params, :session => session, :request_url => request_url}}})
  res.code == 201
end

.reset!Object



47
48
49
50
51
52
# File 'lib/exceptio/client.rb', line 47

def self.reset!
  @application = nil
  @app_key = nil
  @configured = false
  @ignored_exceptions = DEFAULT_IGNORED_EXCEPTIONS.clone
end