Module: Errship3::Rescuers

Defined in:
lib/errship3.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



16
17
18
19
20
21
22
# 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

Instance Method Details

#errship3_standard(errship3_scope = false) ⇒ Object

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



37
38
39
40
41
# 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) ⇒ Object

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



45
46
47
48
49
50
51
52
53
# 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) ⇒ Object



30
31
32
33
# 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) ⇒ Object



24
25
26
27
28
# 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