Module: WillPaginate::Railtie::ShowExceptionsPatch

Extended by:
ActiveSupport::Concern
Defined in:
lib/will_paginate/railtie.rb

Overview

Extending the exception handler middleware so it properly detects WillPaginate::InvalidPage regardless of it being a tag module.

Instance Method Summary collapse

Instance Method Details

#status_code_with_paginate(exception = @exception) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/will_paginate/railtie.rb', line 39

def status_code_with_paginate(exception = @exception)
  actual_exception = if exception.respond_to?(:cause)
    exception.cause || exception
  elsif exception.respond_to?(:original_exception)
    exception.original_exception
  else
    exception
  end

  if actual_exception.is_a?(WillPaginate::InvalidPage)
    Rack::Utils.status_code(:not_found)
  else
    original_method = method(:status_code_without_paginate)
    if original_method.arity != 0
      original_method.call(exception)
    else
      original_method.call()
    end
  end
end