Sha256: 30089741feebc5815c92fec9110dc40481af78feaec350174abd74fec60325a2

Contents?: true

Size: 642 Bytes

Versions: 3

Compression:

Stored size: 642 Bytes

Contents

# https://guides.rubyonrails.org/configuring.html#config-exceptions-app
module Panda
  module CMS
    class ExceptionsApp
      def initialize(exceptions_app:)
        @exceptions_app = exceptions_app
      end

      def call(env)
        request = ActionDispatch::Request.new(env)

        fallback_to_html_format_if_invalid_mime_type(request)

        @exceptions_app.call(env)
      end

      private

      def fallback_to_html_format_if_invalid_mime_type(request)
        request.formats
      rescue ActionDispatch::Http::MimeNegotiation::InvalidType
        request.set_header "CONTENT_TYPE", "text/html"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
panda-cms-0.7.3 lib/panda/cms/exceptions_app.rb
panda-cms-0.7.2 lib/panda/cms/exceptions_app.rb
panda-cms-0.7.0 lib/panda/cms/exceptions_app.rb