flail 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -24,23 +24,23 @@ Add an initializer to configure (or call configure during application startup):
24
24
  Flail.configure do
25
25
  # configure a custom handler for the error payload
26
26
  # don't call if you want to use the default http post handler
27
- handler do |payload|
27
+ handle do |payload|
28
28
  end
29
29
 
30
30
  # endpoint for default handler
31
- endpoint "https://flail.net/swing"
31
+ url "https://flail.net/swing"
32
32
 
33
33
  # environment of application, defaults to Rails.env
34
34
  # included in payload
35
- env "production"
35
+ environment "production"
36
36
 
37
37
  # hostname to use of server, defaults to Socket.gethostname
38
38
  # included in payload
39
39
  host Socket.gethostname
40
40
 
41
- # arbitrary api key which can identify
41
+ # arbitrary tag (api key) which can identify
42
42
  # your project or be anything else
43
- api "custom_key"
43
+ tagged "custom_key"
44
44
  end
45
45
  ```
46
46
 
@@ -1,5 +1,15 @@
1
1
  class Flail
2
2
  class Configuration
3
+ # for the default handler
4
+ HTTP_ERRORS = [Timeout::Error,
5
+ Errno::EINVAL,
6
+ Errno::ECONNRESET,
7
+ EOFError,
8
+ Net::HTTPBadResponse,
9
+ Net::HTTPHeaderSyntaxError,
10
+ Net::ProtocolError,
11
+ Errno::ECONNREFUSED].freeze
12
+
3
13
  # custom handler for payloads
4
14
  attr_reader :handler
5
15
 
@@ -16,7 +26,7 @@ class Flail
16
26
  attr_reader :secure_endpoint
17
27
 
18
28
  # api key to use with payloads
19
- attr_reader :api_key
29
+ attr_reader :tag
20
30
 
21
31
 
22
32
  def handle(&block)
@@ -39,8 +49,8 @@ class Flail
39
49
  @hostname = value
40
50
  end
41
51
 
42
- def api(value)
43
- @api_key = value
52
+ def tagged(value)
53
+ @tag = value
44
54
  end
45
55
 
46
56
  def defaults!
@@ -64,7 +74,7 @@ class Flail
64
74
  end
65
75
 
66
76
  begin
67
- http.post(url.path, payload, HEADERS)
77
+ http.post(url.path, payload, {'Content-type' => 'application/json', 'Accept' => 'application/json'})
68
78
  rescue *HTTP_ERRORS => e
69
79
  nil
70
80
  end
@@ -11,7 +11,11 @@ class Flail
11
11
  # Helpers
12
12
  #
13
13
  def request
14
- @request ||= ActionDispatch::Request.new(@env)
14
+ @request ||= if @env['flail.request']
15
+ @env['flail.request']
16
+ else
17
+ ActionDispatch::Request.new(@env)
18
+ end
15
19
  end
16
20
 
17
21
  def controller
@@ -37,27 +41,31 @@ class Flail
37
41
  end
38
42
 
39
43
  def extract
40
- @extract ||= {}.tap do |info|
41
- info[:class_name] = @exception.class.to_s # @exception class
42
- info[:message] = @exception.to_s # error message
43
- info[:trace] = @exception.backtrace.to_json # backtrace of error
44
- info[:target_url] = request.url # url of request
45
- info[:referer_url] = request.referer # referer
46
- info[:params] = request.params.to_json # request parameters
47
- info[:user_agent] = request.user_agent # user agent
48
- info[:user] = self.user.to_json # current user
44
+ @extract ||= begin
45
+ info = {}
49
46
 
50
- # special variables
51
- info[:environment] = Flail.configuration.env
52
- info[:hostname] = Flail.configuration.hostname
53
- info[:api_key] = Flail.configuration.api_key
54
- end
47
+ info[:class_name] = @exception.class.to_s # @exception class
48
+ info[:message] = @exception.to_s # error message
49
+ info[:trace] = @exception.backtrace.to_json # backtrace of error
50
+ info[:target_url] = request.url # url of request
51
+ info[:referer_url] = request.referer # referer
52
+ info[:parameters] = request.params.to_json # request parameters
53
+ info[:user_agent] = request.user_agent # user agent
54
+ info[:user] = self.user.to_json # current user
55
+
56
+ # special variables
57
+ info[:environment] = Flail.configuration.env
58
+ info[:hostname] = Flail.configuration.hostname
59
+ info[:tag] = Flail.configuration.tag
60
+
61
+ info
62
+ end
55
63
  end
56
64
 
57
65
  def ignore?
58
66
  # Ignore requests with user agent string matching
59
67
  # this regxp as they are surely made by bots
60
- if @request.user_agent =~ /\b(Baidu|Gigabot|Googlebot|libwww-perl|lwp-trivial|msnbot|SiteUptime|Slurp|WordPress|ZIBB|ZyBorg|Yandex|Jyxobot|Huaweisymantecspider|ApptusBot)\b/i
68
+ if request.user_agent =~ /\b(Baidu|Gigabot|Googlebot|libwww-perl|lwp-trivial|msnbot|SiteUptime|Slurp|WordPress|ZIBB|ZyBorg|Yandex|Jyxobot|Huaweisymantecspider|ApptusBot)\b/i
61
69
  return true
62
70
  end
63
71
 
data/lib/flail/rack.rb CHANGED
@@ -1,24 +1,22 @@
1
1
  class Flail
2
- module Handlers
3
- class Middleware
4
- def initialize(app)
5
- @app = app
6
- end
7
-
8
- def call(env)
9
- begin
10
- response = @app.call(env)
11
- rescue Exception => exception
12
- Flail::Exception.new(env, exception).handle!
13
- raise
14
- end
2
+ class Rack
3
+ def initialize(app)
4
+ @app = app
5
+ end
15
6
 
16
- if env['rack.exception']
17
- Flail::Exception.new(env, env['rack.exception']).handle!
18
- end
7
+ def call(env)
8
+ begin
9
+ response = @app.call(env)
10
+ rescue Exception => exception
11
+ Flail::Exception.new(env, exception).handle!
12
+ raise
13
+ end
19
14
 
20
- response
15
+ if env['rack.exception']
16
+ Flail::Exception.new(env, env['rack.exception']).handle!
21
17
  end
18
+
19
+ response
22
20
  end
23
21
  end
24
22
  end
@@ -13,6 +13,7 @@ class Flail
13
13
  # but uses any custom processing that is defined with
14
14
  # Rails 2's exception helpers.
15
15
  def rescue_action_in_public_with_flail(exception)
16
+ request.env['flail.request'] = request
16
17
  Flail::Exception.new(request.env, exception).handle!
17
18
  rescue_action_in_public_without_flail(exception)
18
19
  end
data/lib/flail/railtie.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  class Flail
2
2
  class Railtie < ::Rails::Railtie
3
3
  initializer "flail.use_rack_middleware" do |app|
4
- app.config.middleware.insert 0, "Flail::Rack"
4
+ app.config.middleware.insert 0, Flail::Rack
5
5
  end
6
6
 
7
7
  config.after_initialize do
data/lib/flail/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Flail
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-27 00:00:00.000000000 Z
12
+ date: 2012-08-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake