Module: Cms::ErrorHandling

Defined in:
lib/cms/error_handling.rb

Defined Under Namespace

Classes: NotifierService

Instance Method Summary collapse

Instance Method Details

#handle_internal_access_denied(exception) ⇒ Object



30
31
32
33
34
# File 'lib/cms/error_handling.rb', line 30

def handle_internal_access_denied(exception)
  render :layout => 'cms/application',
         :template => 'cms/shared/access_denied',
         :status => 403
end

#handle_server_error(exception, status = :internal_server_error) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/cms/error_handling.rb', line 20

def handle_server_error(exception, status=:internal_server_error)
  log_complete_stacktrace(exception)
  with_format('html') do
    render :layout => 'cms/application',
           :template => 'cms/shared/error',
           :status => status,
           :locals => {:exception => exception}
  end
end

#log_complete_stacktrace(exception) ⇒ Object

Print the underlying stack trace to the logs for debugging. Should be human readable (i.e. line breaks) See stackoverflow.com/questions/228441/how-do-i-log-the-entire-trace-back-of-a-ruby-exception-using-the-default-rails-l for discussion of implementation



39
40
41
42
# File 'lib/cms/error_handling.rb', line 39

def log_complete_stacktrace(exception)
  logger.error "#{exception.message}\n#{exception.backtrace.join("\n")}"
  NotifierService.notify exception
end

#with_format(format, &block) ⇒ Object

Ensures the entire render stack applies a specific format For example, this allows missing jpg’s to throw the proper error as opposed to 500



12
13
14
15
16
17
18
# File 'lib/cms/error_handling.rb', line 12

def with_format(format, &block)
  old_formats = self.formats
  self.formats = [format]
  result = block.call
  self.formats = old_formats
  result
end