File: errors.rb

package info (click to toggle)
ruby-gaffe 1.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 204 kB
  • sloc: ruby: 221; makefile: 7
file content (31 lines) | stat: -rw-r--r-- 790 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
module Gaffe
  module Errors
    extend ActiveSupport::Concern

    included do
      before_action :fetch_exception, only: %w(show)
      before_action :append_view_paths
      layout 'error'
    end

    def show
      render "errors/#{@rescue_response}", status: @status_code
    rescue ActionView::MissingTemplate
      render 'errors/internal_server_error', status: 500
    end

  protected

    def fetch_exception
      @exception = request.env['action_dispatch.exception']
      @status_code = ActionDispatch::ExceptionWrapper.new(request.env, @exception).status_code
      @rescue_response = ActionDispatch::ExceptionWrapper.rescue_responses[@exception.class.name]
    end

  private

    def append_view_paths
      append_view_path Gaffe.root.join('app/views')
    end
  end
end