errplane 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/errplane.rb +1 -3
- data/lib/errplane/configuration.rb +12 -2
- data/lib/errplane/railtie.rb +4 -4
- data/lib/errplane/transmitter.rb +3 -3
- data/lib/errplane/version.rb +1 -1
- data/spec/integration/exceptions_spec.rb +9 -3
- data/spec/unit/errplane_spec.rb +26 -0
- metadata +3 -1
data/lib/errplane.rb
CHANGED
@@ -19,8 +19,6 @@ require "errplane/rack"
|
|
19
19
|
require "errplane/railtie" #if defined?(Rails)
|
20
20
|
|
21
21
|
module Errplane
|
22
|
-
API_HOST = "api.errplane.com"
|
23
|
-
|
24
22
|
class << self
|
25
23
|
attr_writer :configuration
|
26
24
|
attr_accessor :transmitter
|
@@ -39,7 +37,7 @@ module Errplane
|
|
39
37
|
end
|
40
38
|
|
41
39
|
def ignorable_exception?(exception)
|
42
|
-
|
40
|
+
configuration.ignore_current_environment? || configuration.ignored_exceptions.include?(exception.class.to_s)
|
43
41
|
end
|
44
42
|
|
45
43
|
private
|
@@ -1,19 +1,29 @@
|
|
1
1
|
module Errplane
|
2
2
|
class Configuration
|
3
3
|
attr_accessor :api_key
|
4
|
+
attr_accessor :api_host
|
4
5
|
attr_accessor :application_id
|
5
6
|
|
6
7
|
attr_accessor :logger
|
7
|
-
attr_accessor :
|
8
|
-
attr_accessor :
|
8
|
+
attr_accessor :rails_environment
|
9
|
+
attr_accessor :rails_root
|
9
10
|
attr_accessor :framework
|
10
11
|
attr_accessor :ignored_exceptions
|
12
|
+
attr_accessor :ignored_environments
|
11
13
|
|
14
|
+
DEFAULT_API_HOST = "api.errplane.com"
|
12
15
|
DEFAULT_IGNORED_EXCEPTIONS = %w{ActiveRecord::RecordNotFound
|
13
16
|
ActionController::RoutingError}
|
17
|
+
DEFAULT_IGNORED_ENVIRONMENTS = %w{development test cucumber selenium}
|
14
18
|
|
15
19
|
def initialize
|
20
|
+
@api_host = DEFAULT_API_HOST
|
16
21
|
@ignored_exceptions = DEFAULT_IGNORED_EXCEPTIONS.dup
|
22
|
+
@ignored_environments = DEFAULT_IGNORED_ENVIRONMENTS.dup
|
23
|
+
end
|
24
|
+
|
25
|
+
def ignore_current_environment?
|
26
|
+
return self.ignored_environments.include?(self.rails_environment)
|
17
27
|
end
|
18
28
|
end
|
19
29
|
end
|
data/lib/errplane/railtie.rb
CHANGED
@@ -12,10 +12,10 @@ module Errplane
|
|
12
12
|
|
13
13
|
config.after_initialize do
|
14
14
|
Errplane.configure(true) do |config|
|
15
|
-
config.logger
|
16
|
-
config.
|
17
|
-
config.
|
18
|
-
config.framework
|
15
|
+
config.logger ||= ::Rails.logger
|
16
|
+
config.rails_environment ||= ::Rails.env
|
17
|
+
config.rails_root ||= ::Rails.root
|
18
|
+
config.framework = "Rails #{::Rails::VERSION::STRING}"
|
19
19
|
end
|
20
20
|
|
21
21
|
if defined?(::ActionDispatch::DebugExceptions)
|
data/lib/errplane/transmitter.rb
CHANGED
@@ -7,9 +7,9 @@ module Errplane
|
|
7
7
|
http = initialize_http_connection
|
8
8
|
data = black_box.to_json
|
9
9
|
response = begin
|
10
|
-
url = "/api/v1/applications/#{Errplane.configuration.application_id}/exceptions/#{Errplane.configuration.
|
10
|
+
url = "/api/v1/applications/#{Errplane.configuration.application_id}/exceptions/#{Errplane.configuration.rails_environment}?api_key=#{Errplane.configuration.api_key}"
|
11
11
|
::Rails.logger.info(url)
|
12
|
-
http.post("/api/v1/applications/#{Errplane.configuration.application_id}/exceptions/#{Errplane.configuration.
|
12
|
+
http.post("/api/v1/applications/#{Errplane.configuration.application_id}/exceptions/#{Errplane.configuration.rails_environment}?api_key=#{Errplane.configuration.api_key}", data)
|
13
13
|
rescue Exception => e
|
14
14
|
e
|
15
15
|
end
|
@@ -27,7 +27,7 @@ module Errplane
|
|
27
27
|
|
28
28
|
private
|
29
29
|
def initialize_http_connection
|
30
|
-
connection = Net::HTTP.new(
|
30
|
+
connection = Net::HTTP.new(Errplane.configuration.api_host, "80")
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
data/lib/errplane/version.rb
CHANGED
@@ -1,13 +1,19 @@
|
|
1
1
|
require File.dirname(__FILE__) + "/integration_helper"
|
2
2
|
|
3
3
|
feature "exception handling" do
|
4
|
+
before do
|
5
|
+
Errplane.configure do |config|
|
6
|
+
config.ignored_environments = %w{development}
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
4
10
|
describe "in an action that raises an exception" do
|
5
11
|
scenario "should make an HTTP call to the API" do
|
6
|
-
stub_request(:post, "#{Errplane
|
12
|
+
stub_request(:post, "#{Errplane.configuration.api_host}/exceptions").to_return(status: 200)
|
7
13
|
|
8
14
|
lambda { visit new_widget_path }.should raise_error
|
9
15
|
|
10
|
-
assert_requested :post, "#{Errplane
|
16
|
+
assert_requested :post, "#{Errplane.configuration.api_host}/api/v1/applications/#{Errplane.configuration.application_id}/exceptions/test?api_key=f123-e456-d789c012"
|
11
17
|
end
|
12
18
|
end
|
13
19
|
|
@@ -15,7 +21,7 @@ feature "exception handling" do
|
|
15
21
|
scenario "should not make an HTTP call to the API" do
|
16
22
|
lambda { visit widgets_path }.should_not raise_error
|
17
23
|
|
18
|
-
assert_not_requested :post, "#{Errplane
|
24
|
+
assert_not_requested :post, "#{Errplane.configuration.api_host}/api/v1/applications/#{Errplane.configuration.application_id}/exceptions/test?api_key=f123-e456-d789c012"
|
19
25
|
end
|
20
26
|
end
|
21
27
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Errplane do
|
4
|
+
describe ".ignorable_exception?" do
|
5
|
+
it "should be true for exception types specified in the configuration" do
|
6
|
+
class DummyException < Exception; end
|
7
|
+
exception = DummyException.new
|
8
|
+
|
9
|
+
Errplane.configure do |config|
|
10
|
+
config.ignored_exceptions << 'DummyException'
|
11
|
+
end
|
12
|
+
|
13
|
+
Errplane.ignorable_exception?(exception).should be_true
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should be true for exception types specified in the configuration" do
|
17
|
+
exception = ActionController::RoutingError.new("foo")
|
18
|
+
Errplane.ignorable_exception?(exception).should be_true
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should be false for valid exceptions" do
|
22
|
+
exception = ZeroDivisionError.new
|
23
|
+
Errplane.ignorable_exception?(exception).should be_false
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: errplane
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -49,6 +49,7 @@ files:
|
|
49
49
|
- spec/internal/public/favicon.ico
|
50
50
|
- spec/spec_helper.rb
|
51
51
|
- spec/unit/black_box_spec.rb
|
52
|
+
- spec/unit/errplane_spec.rb
|
52
53
|
homepage: http://errplane.com
|
53
54
|
licenses: []
|
54
55
|
post_install_message:
|
@@ -88,3 +89,4 @@ test_files:
|
|
88
89
|
- spec/internal/public/favicon.ico
|
89
90
|
- spec/spec_helper.rb
|
90
91
|
- spec/unit/black_box_spec.rb
|
92
|
+
- spec/unit/errplane_spec.rb
|