Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Turn exception_notification Rails agnostic

Dont believe me?! then, checkout the sinatra example. ;P
  • Loading branch information...
commit 538abb5c1f44aa8832230306c1d7e235bcde8b73 1 parent 0147e2d
@jweslley jweslley authored
View
2  Gemfile
@@ -1,3 +1,3 @@
-source "http://rubygems.org"
+source "https://rubygems.org"
gemspec
View
3  Gemfile.lock
@@ -3,9 +3,10 @@ PATH
specs:
exception_notification (3.0.1)
actionmailer (>= 3.0.4)
+ activesupport (>= 3.0.4)
GEM
- remote: http://rubygems.org/
+ remote: https://rubygems.org/
specs:
actionmailer (3.2.6)
actionpack (= 3.2.6)
View
8 examples/sinatra/Gemfile
@@ -0,0 +1,8 @@
+source "https://rubygems.org"
+
+gem "exception_notification", path: "../../"
+
+gem "thin", "~> 1.5.1"
+gem "sinatra", "~> 1.3.5"
+gem "foreman"
+gem "mailcatcher"
View
95 examples/sinatra/Gemfile.lock
@@ -0,0 +1,95 @@
+PATH
+ remote: ../../
+ specs:
+ exception_notification (3.0.1)
+ actionmailer (>= 3.0.4)
+ activesupport (>= 3.0.4)
+
+GEM
+ remote: https://rubygems.org/
+ specs:
+ actionmailer (3.2.13)
+ actionpack (= 3.2.13)
+ mail (~> 2.5.3)
+ actionpack (3.2.13)
+ activemodel (= 3.2.13)
+ activesupport (= 3.2.13)
+ builder (~> 3.0.0)
+ erubis (~> 2.7.0)
+ journey (~> 1.0.4)
+ rack (~> 1.4.5)
+ rack-cache (~> 1.2)
+ rack-test (~> 0.6.1)
+ sprockets (~> 2.2.1)
+ activemodel (3.2.13)
+ activesupport (= 3.2.13)
+ builder (~> 3.0.0)
+ activesupport (3.2.13)
+ i18n (= 0.6.1)
+ multi_json (~> 1.0)
+ builder (3.0.4)
+ daemons (1.1.9)
+ erubis (2.7.0)
+ eventmachine (1.0.3)
+ foreman (0.61.0)
+ thor (>= 0.13.6)
+ haml (4.0.2)
+ tilt
+ hike (1.2.1)
+ i18n (0.6.1)
+ journey (1.0.4)
+ mail (2.5.3)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mailcatcher (0.5.11)
+ activesupport (~> 3.0)
+ eventmachine (~> 1.0.0)
+ haml (>= 3.1, < 5)
+ mail (~> 2.3)
+ sinatra (~> 1.2)
+ skinny (~> 0.2.3)
+ sqlite3 (~> 1.3)
+ thin (~> 1.5.0)
+ mime-types (1.22)
+ multi_json (1.7.2)
+ polyglot (0.3.3)
+ rack (1.4.5)
+ rack-cache (1.2)
+ rack (>= 0.4)
+ rack-protection (1.5.0)
+ rack
+ rack-test (0.6.2)
+ rack (>= 1.0)
+ sinatra (1.3.6)
+ rack (~> 1.4)
+ rack-protection (~> 1.3)
+ tilt (~> 1.3, >= 1.3.3)
+ skinny (0.2.3)
+ eventmachine (~> 1.0.0)
+ thin (~> 1.5.0)
+ sprockets (2.2.2)
+ hike (~> 1.2)
+ multi_json (~> 1.0)
+ rack (~> 1.0)
+ tilt (~> 1.1, != 1.3.0)
+ sqlite3 (1.3.7)
+ thin (1.5.1)
+ daemons (>= 1.0.9)
+ eventmachine (>= 0.12.6)
+ rack (>= 1.0.0)
+ thor (0.18.1)
+ tilt (1.3.6)
+ treetop (1.4.12)
+ polyglot
+ polyglot (>= 0.3.1)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ exception_notification!
+ foreman
+ mailcatcher
+ sinatra (~> 1.3.5)
+ thin (~> 1.5.1)
View
2  examples/sinatra/Procfile
@@ -0,0 +1,2 @@
+web: bundle exec thin start --port 3000
+mail: bundle exec mailcatcher --foreground --smtp-port 1025 --http-port 1080
View
11 examples/sinatra/README.md
@@ -0,0 +1,11 @@
+# Using Exception Notification with Sinatra
+
+## Quick start
+
+ git clone git@github.com:smartinez87/exception_notification.git
+ cd exception_notification/examples/sinatra
+ bundle install
+ bundle exec foreman start
+
+
+The last command starts two services, a smtp server and the sinatra app itself. Thus, visit [http://localhost:1080/](http://localhost:1080/) to check the emails sent and, in a separated tab, visit [http://localhost:3000](http://localhost:3000) and cause some errors. For more info, use the [source](https://github.com/smartinez87/exception_notification/blob/master/examples/sinatra/sinatra_app.rb) Luke.
View
3  examples/sinatra/config.ru
@@ -0,0 +1,3 @@
+require ::File.expand_path('../sinatra_app', __FILE__)
+
+run SinatraApp
View
28 examples/sinatra/sinatra_app.rb
@@ -0,0 +1,28 @@
+require 'rubygems'
+require 'bundler/setup'
+require 'sinatra/base'
+require 'exception_notification'
+
+class SinatraApp < Sinatra::Base
+ use ExceptionNotifier,
+ :email => {
+ :email_prefix => "[Example] ",
+ :sender_address => %{"notifier" <notifier@example.com>},
+ :exception_recipients => %w{exceptions@example.com},
+ :smtp_settings => { :address => "localhost", :port => 1025 }
+ }
+
+ get '/' do
+ raise StandardError, "ERROR: #{params[:error]}" unless params[:error].blank?
+ 'Everything is fine! Now, lets break things clicking <a href="/?error=ops"> here </a>. Dont forget to see the emails at <a href="http://localhost:1080">mailcatcher</a> !'
+ end
+
+ get '/background_notification' do
+ begin
+ 1/0
+ rescue Exception => e
+ ExceptionNotifier.notify_exception(e, :data => {:msg => "Cannot divide by zero!"})
+ end
+ 'Check email at <a href="http://localhost:1080">mailcatcher</a>.'
+ end
+end
View
1  exception_notification.gemspec
@@ -12,6 +12,7 @@ Gem::Specification.new do |s|
s.require_path = 'lib'
s.add_dependency("actionmailer", ">= 3.0.4")
+ s.add_dependency("activesupport", ">= 3.0.4")
s.add_development_dependency "tinder", "~> 1.8"
s.add_development_dependency "httparty", "~> 0.10.2"
View
4 lib/exception_notifier.rb
@@ -1,4 +1,6 @@
-require 'action_dispatch'
+require 'active_support/deprecation'
+require 'active_support/core_ext/array/wrap'
+require 'active_support/core_ext/string/inflections'
class ExceptionNotifier
View
17 lib/exception_notifier/email_notifier.rb
@@ -1,4 +1,5 @@
require 'action_mailer'
+require 'action_dispatch'
require 'pp'
class ExceptionNotifier
@@ -107,15 +108,13 @@ def exception_notification(env, exception, options={}, default_options={})
def background_exception_notification(exception, options={}, default_options={})
load_custom_views
- if @notifier = Rails.application.config.middleware.detect{ |x| x.klass == ExceptionNotifier }
- @options = options.reverse_merge(@notifier.args.first || {}).reverse_merge(default_options)
- @exception = exception
- @backtrace = exception.backtrace || []
- @sections = @options[:background_sections]
- @data = options[:data] || {}
+ @exception = exception
+ @options = options.reverse_merge(default_options)
+ @backtrace = exception.backtrace || []
+ @sections = @options[:background_sections]
+ @data = options[:data] || {}
- compose_email
- end
+ compose_email
end
private
@@ -149,8 +148,6 @@ def inspect_object(object)
case object
when Hash, Array
object.inspect
- when ActionController::Base
- "#{object.controller_name}##{object.action_name}"
else
object.to_s
end
View
2  lib/exception_notifier/notifier.rb
@@ -1,3 +1,5 @@
+require 'active_support/deprecation'
+
class ExceptionNotifier
class Notifier
View
2  lib/exception_notifier/views/exception_notifier/_request.html.erb
@@ -1,5 +1,7 @@
* URL : <%= raw @request.url %>
* IP address: <%= raw @request.remote_ip %>
* Parameters: <%= raw @request.filtered_parameters.inspect %>
+<% if defined?(Rails) %>
* Rails root: <%= raw Rails.root %>
+<% end %>
* Timestamp : <%= raw Time.current %>
View
2  lib/exception_notifier/views/exception_notifier/_request.text.erb
@@ -1,5 +1,7 @@
* URL : <%= raw @request.url %>
* IP address: <%= raw @request.remote_ip %>
* Parameters: <%= raw @request.filtered_parameters.inspect %>
+<% if defined?(Rails) %>
* Rails root: <%= raw Rails.root %>
+<% end %>
* Timestamp : <%= raw Time.current %>
View
2  lib/exception_notifier/views/exception_notifier/_session.html.erb
@@ -1,2 +1,2 @@
-* session id: <%= @request.ssl? ? "[FILTERED]" : (raw (@request.session['session_id'] || @request.env["rack.session.options"][:id]).inspect.html_safe) %>
+* session id: <%= @request.ssl? ? "[FILTERED]" : (raw (@request.session['session_id'] || (@request.env["rack.session.options"] and @request.env["rack.session.options"][:id])).inspect.html_safe) %>
* data: <%= raw PP.pp(@request.session, "") %>
View
2  lib/exception_notifier/views/exception_notifier/_session.text.erb
@@ -1,2 +1,2 @@
-* session id: <%= @request.ssl? ? "[FILTERED]" : (raw (@request.session['session_id'] || @request.env["rack.session.options"][:id]).inspect.html_safe) %>
+* session id: <%= @request.ssl? ? "[FILTERED]" : (raw (@request.session['session_id'] || (@request.env["rack.session.options"] and @request.env["rack.session.options"][:id])).inspect.html_safe) %>
* data: <%= raw PP.pp(@request.session, "") %>
Please sign in to comment.
Something went wrong with that request. Please try again.