Sha256: 20e50069f1d018bed6d6be443dedb1c8dc669b027c0ff5927fcee08af43e8f53

Contents?: true

Size: 773 Bytes

Versions: 12

Compression:

Stored size: 773 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)

        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

12 entries across 12 versions & 1 rubygems

Version Path
locomotivecms-3.1.0.rc2 app/controllers/locomotive/concerns/exception_controller.rb
locomotivecms-3.1.0.rc1 app/controllers/locomotive/concerns/exception_controller.rb
locomotivecms-3.0.1 app/controllers/locomotive/concerns/exception_controller.rb
locomotivecms-3.0.0 app/controllers/locomotive/concerns/exception_controller.rb
locomotivecms-3.0.0.rc7 app/controllers/locomotive/concerns/exception_controller.rb
locomotivecms-3.0.0.rc6 app/controllers/locomotive/concerns/exception_controller.rb
locomotivecms-3.0.0.rc5 app/controllers/locomotive/concerns/exception_controller.rb
locomotivecms-3.0.0.rc4 app/controllers/locomotive/concerns/exception_controller.rb
locomotivecms-3.0.0.rc3 app/controllers/locomotive/concerns/exception_controller.rb
locomotivecms-3.0.0.rc2 app/controllers/locomotive/concerns/exception_controller.rb
locomotivecms-3.0.0.rc1 app/controllers/locomotive/concerns/exception_controller.rb
locomotivecms-3.0.0.pre.beta.1 app/controllers/locomotive/concerns/exception_controller.rb