Sha256: 9b6af0b0dcf2a8c3e63836dc2b4e2e447008f5d9d8fcec56d6f4464262018624

Contents?: true

Size: 884 Bytes

Versions: 27

Compression:

Stored size: 884 Bytes

Contents

module Locomotive
  module Concerns
    module ExceptionController

      extend ActiveSupport::Concern

      included do
        rescue_from Exception, with: :render_exception
      end

      private

      def render_exception(exception)
        ::Locomotive.log "[ApplicationError] #{exception.inspect}"

        status = (case exception
        when ::Mongoid::Errors::DocumentNotFound  then 404
        else
          raise exception unless request.xhr?
          500
        end)

        puts "Backtrace:\n\t#{exception.backtrace.join("\n\t")}" if Rails.env.development? || Rails.env.test?

        if request.xhr?
          render json: { error: exception.message }, status: status, layout: false
        else
          flash[:alert] = exception.message
          redirect_to current_site ? dashboard_path(current_site) : sites_path
        end
      end

    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
locomotivecms-4.2.0.alpha2 app/controllers/locomotive/concerns/exception_controller.rb
locomotivecms-4.2.0.alpha1 app/controllers/locomotive/concerns/exception_controller.rb
locomotivecms-4.1.1 app/controllers/locomotive/concerns/exception_controller.rb
locomotivecms-4.1.0 app/controllers/locomotive/concerns/exception_controller.rb
locomotivecms-4.1.0.rc1 app/controllers/locomotive/concerns/exception_controller.rb
locomotivecms-4.0.3 app/controllers/locomotive/concerns/exception_controller.rb
locomotivecms-4.0.2 app/controllers/locomotive/concerns/exception_controller.rb
locomotivecms-4.0.1 app/controllers/locomotive/concerns/exception_controller.rb
locomotivecms-4.0.0 app/controllers/locomotive/concerns/exception_controller.rb
locomotivecms-4.0.0.rc0 app/controllers/locomotive/concerns/exception_controller.rb
locomotivecms-4.0.0.alpha3 app/controllers/locomotive/concerns/exception_controller.rb
locomotivecms-3.4.1 app/controllers/locomotive/concerns/exception_controller.rb
locomotivecms-4.0.0.alpha2 app/controllers/locomotive/concerns/exception_controller.rb
locomotivecms-4.0.0.alpha1 app/controllers/locomotive/concerns/exception_controller.rb
locomotivecms-3.4.0 app/controllers/locomotive/concerns/exception_controller.rb
locomotivecms-3.3.0 app/controllers/locomotive/concerns/exception_controller.rb
locomotivecms-3.3.0.rc3 app/controllers/locomotive/concerns/exception_controller.rb
locomotivecms-3.3.0.rc2 app/controllers/locomotive/concerns/exception_controller.rb
locomotivecms-3.1.2 app/controllers/locomotive/concerns/exception_controller.rb
locomotivecms-3.2.1 app/controllers/locomotive/concerns/exception_controller.rb