module Errship3::Rescuers

Public Class Methods

included(base) click to toggle source
# File lib/errship3.rb, line 16
def self.included(base)
  unless Rails.application.config.consider_all_requests_local
    base.rescue_from ActionController::RoutingError, :with => :render_404_error
    base.rescue_from ActionController::UnknownController, :with => :render_404_error
    base.rescue_from ::AbstractController::ActionNotFound, :with => :render_404_error
  end
end

Public Instance Methods

errship3_standard(errship3_scope = false) click to toggle source

A blank page with just the layout and flash message, which can be redirected to when all else fails.

# File lib/errship3.rb, line 37
def errship3_standard(errship3_scope = false)
  flash[:error] ||= 'An unknown error has occurred, or you have reached this page by mistake.'
  render :template => '/errship3/standard', :locals => {
    :status_code => 500, :errship3_scope => errship3_scope }
end
flashback(error_message, exception = nil) click to toggle source

Set the error flash and attempt to redirect back. If RedirectBackError is raised, redirect to error_path instead.

# File lib/errship3.rb, line 45
def flashback(error_message, exception = nil)
  airbrake_class.send(:notify, exception) if airbrake_class
  flash[:error] = error_message
  begin
    redirect_to :back
  rescue ActionController::RedirectBackError
    redirect_to error_path
  end
end
render_404_error(exception = nil, errship3_scope = false) click to toggle source
# File lib/errship3.rb, line 30
def render_404_error(exception = nil, errship3_scope = false)
  render :template => '/errship3/standard', :locals => {
    :status_code => 404, :errship3_scope => errship3_scope }, :status => (Errship3.status_code_success ? 200 : 404)
end
render_error(exception, errship3_scope = false) click to toggle source
# File lib/errship3.rb, line 24
def render_error(exception, errship3_scope = false)
  airbrake_class.send(:notify, exception) if airbrake_class
  render :template => '/errship3/standard', :locals => {
    :status_code => 500, :errship3_scope => errship3_scope }, :status => (Errship3.status_code_success ? 200 : 500)
end

Private Instance Methods

airbrake_class() click to toggle source
# File lib/errship3.rb, line 56
def airbrake_class
  return Airbrake if defined?(Airbrake)
  return HoptoadNotifier if defined?(HoptoadNotifier)
  return false
end