lib/egregious.rb in egregious-0.2.10 vs lib/egregious.rb in egregious-0.2.12

- old
+ new

@@ -94,11 +94,11 @@ Mongoid::Errors::InvalidFind=>status_code(:bad_request), Mongoid::Errors::DocumentNotFound=>status_code(:not_found), Mongoid::Errors::Validations=>status_code(:unprocessable_entity) }) - if Mongoid::VERSION > '3' + if defined?(Mongoid::VERSION) && Mongoid::VERSION > '3' exception_codes.merge!({ Mongoid::Errors::ReadonlyAttribute=>status_code(:forbidden), Mongoid::Errors::UnknownAttribute=>status_code(:bad_request) }) end @@ -135,11 +135,13 @@ # a little helper to help us clean up the backtrace # if root is defined it removes that, for rails it takes care of that def clean_backtrace(exception) if backtrace = exception.backtrace if Egregious.root - backtrace.map { |line| line.sub Egregious.root, '' } + backtrace.map { |line| + line.sub Egregious.root.to_s, '' + } else backtrace end end end @@ -171,11 +173,11 @@ # this method will lookup the exception code for a given exception class # if the exception is not in our map then see if the class responds to :http_status # if not it will return 500 def status_code_for_exception(exception) - Egregious.status_code_for_exception(exception) + Egregious.status_code_for_exception(exception) end def self.status_code_for_exception(exception) status_code(self.exception_codes[exception.class] || (exception.respond_to?(:http_status) ? (exception.http_status||:internal_server_error) : :internal_server_error)) @@ -202,53 +204,45 @@ notify_airbrake(exception) end # override this if you want to control what gets sent to airbrake def notify_airbrake(exception) - # for ancient clients - can probably remove - HoptoadNotifier.notify(exception) if defined?(HoptoadNotifier) - # tested with airbrake 3.1.15 and 4.2.1 - env['airbrake.error_id'] = Airbrake.notify_or_ignore(exception) if defined?(Airbrake) + # tested with airbrake 3.1.15, 4.2.1 and 5.0.5 + if defined?(Airbrake) + if(Airbrake.respond_to?(:notify_or_ignore)) + env['airbrake.error_id'] = Airbrake.notify_or_ignore(exception) # V4 + else + env['airbrake.error_id'] = Airbrake.notify(exception) # V5 + end + end end # override this if you want to change your respond_to behavior def egregious_respond_to(exception) respond_to do |format| status = status_code_for_exception(exception) format.xml { render :xml=> exception.to_xml, :status => status } format.json { render :json=> exception.to_json, :status => status } # render the html page for the status we are returning it exists...if not then render the 500.html page. - format.html { render :file => File.exists?(build_html_file_path(status)) ? + format.html { + # render the rails exception page if we are local/debugging + if(Rails.application.config.consider_all_requests_local || request.local?) + raise exception + else + render :file => File.exists?(build_html_file_path(status)) ? build_html_file_path(status) : build_html_file_path('500'), - :status => status } + :status => status + end + } end end def build_html_file_path(status) File.join(Rails.root, 'public', "#{status_code(status)}.html") end def self.included(base) base.class_eval do rescue_from 'Exception' , :with => :egregious_exception_handler - - unless respond_to?(:flash) - def egregious_flash(exception) - end - end - - unless respond_to?(:respond_to) - def egregious_respond_to(exception) - status = status_code_for_exception(exception) - case params[:format] - when 'xml' then render :xml=> exception.to_xml, :status => status - when 'json' then render :json=> exception.to_json, :status => status - # render the html page for the status we are returning it exists...if not then render the 500.html page. - else render :file => File.exists?(build_html_file_path(status)) ? - build_html_file_path(status) : build_html_file_path('500'), - :status => status - end - end - end end end end