Sha256: 32952f313f19657c9acc85ce36838c83e355033e342507580b8878f01d80261a

Contents?: true

Size: 1.78 KB

Versions: 36

Compression:

Stored size: 1.78 KB

Contents

module Locomotive
  module Steam
    module Middlewares

      class CatchError

        def initialize(app, opts = {})
          @app = app
        end

        def call(env)
          begin
            @app.call(env)
          rescue Exception => e
            handle_exception(e, env)
          end
        end

        protected

        def handle_exception(exception, env)
          # display the application error page if not in the back-office
          raise exception unless env['steam.live_editing']

          ActiveSupport::Notifications.instrument 'locomotive.site.rendering_error', {
            env:        env,
            exception:  exception
          }

          Rails.logger.error "[LiveEditing] " + exception.message + "\n\t" + exception.backtrace.join("\n\t")

          render_error_page
        end

        def render_error_page
          [200, {}, [%(
<html>
  <head>
    <link href="#{bootstrap_stylesheet_url}" rel="stylesheet" type="text/css" />
  </head>
  <body>
    <div class="container">
      <div class="row">
        <div class="col-md-12">
          <img src="#{train_image_url}">

          <div class="alert alert-danger" role="alert">
            <h4 class="text-center">
              We're sorry, but something went wrong.
            </h4>
            <p class="text-center">
              If you are the application owner check the logs for more information.
            </p>
          </div>
        </div>
      </div>
    </div>
  </body>
</html>
          )]]
        end

        def bootstrap_stylesheet_url
          ::ActionController::Base.helpers.stylesheet_url('locomotive/live_editing_error')
        end

        def train_image_url
          ::ActionController::Base.helpers.image_url('locomotive/deadend.png')
        end

      end

    end
  end
end



Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
locomotivecms-4.2.0.alpha2 lib/locomotive/steam/middlewares/catch_error.rb
locomotivecms-4.2.0.alpha1 lib/locomotive/steam/middlewares/catch_error.rb
locomotivecms-4.1.1 lib/locomotive/steam/middlewares/catch_error.rb
locomotivecms-4.1.0 lib/locomotive/steam/middlewares/catch_error.rb
locomotivecms-4.1.0.rc1 lib/locomotive/steam/middlewares/catch_error.rb
locomotivecms-4.0.3 lib/locomotive/steam/middlewares/catch_error.rb
locomotivecms-4.0.2 lib/locomotive/steam/middlewares/catch_error.rb
locomotivecms-4.0.1 lib/locomotive/steam/middlewares/catch_error.rb
locomotivecms-4.0.0 lib/locomotive/steam/middlewares/catch_error.rb
locomotivecms-4.0.0.rc0 lib/locomotive/steam/middlewares/catch_error.rb
locomotivecms-4.0.0.alpha3 lib/locomotive/steam/middlewares/catch_error.rb
locomotivecms-3.4.1 lib/locomotive/steam/middlewares/catch_error.rb
locomotivecms-4.0.0.alpha2 lib/locomotive/steam/middlewares/catch_error.rb
locomotivecms-4.0.0.alpha1 lib/locomotive/steam/middlewares/catch_error.rb
locomotivecms-3.4.0 lib/locomotive/steam/middlewares/catch_error.rb
locomotivecms-3.3.0 lib/locomotive/steam/middlewares/catch_error.rb
locomotivecms-3.3.0.rc3 lib/locomotive/steam/middlewares/catch_error.rb
locomotivecms-3.3.0.rc2 lib/locomotive/steam/middlewares/catch_error.rb
locomotivecms-3.1.2 lib/locomotive/steam/middlewares/catch_error.rb
locomotivecms-3.2.1 lib/locomotive/steam/middlewares/catch_error.rb