flail 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +5 -5
- data/lib/flail/configuration.rb +14 -4
- data/lib/flail/exception.rb +24 -16
- data/lib/flail/rack.rb +15 -17
- data/lib/flail/rails/rescue_action.rb +1 -0
- data/lib/flail/railtie.rb +1 -1
- data/lib/flail/version.rb +1 -1
- metadata +2 -2
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
|
-
|
27
|
+
handle do |payload|
|
28
28
|
end
|
29
29
|
|
30
30
|
# endpoint for default handler
|
31
|
-
|
31
|
+
url "https://flail.net/swing"
|
32
32
|
|
33
33
|
# environment of application, defaults to Rails.env
|
34
34
|
# included in payload
|
35
|
-
|
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
|
-
|
43
|
+
tagged "custom_key"
|
44
44
|
end
|
45
45
|
```
|
46
46
|
|
data/lib/flail/configuration.rb
CHANGED
@@ -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 :
|
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
|
43
|
-
@
|
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,
|
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
|
data/lib/flail/exception.rb
CHANGED
@@ -11,7 +11,11 @@ class Flail
|
|
11
11
|
# Helpers
|
12
12
|
#
|
13
13
|
def request
|
14
|
-
@request ||=
|
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 ||=
|
41
|
-
|
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
|
-
#
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
|
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
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
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
|
-
|
17
|
-
|
18
|
-
|
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
|
-
|
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
data/lib/flail/version.rb
CHANGED
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.
|
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-
|
12
|
+
date: 2012-08-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|