Sha256: 0d8345ca360de9b8956e638b24068533c80bd0508be6176084aa2ec69df633bd

Contents?: true

Size: 819 Bytes

Versions: 1

Compression:

Stored size: 819 Bytes

Contents

module Pakyow
  module Middleware
    class Router
      def initialize(app)
        @app = app
      end

      def call(env)
        catch(:halt) {
          Pakyow.app.router.route!(Pakyow.app.request)
          @app.call(env)
        }
      rescue StandardError => error
        Pakyow.app.request.error = error

        Pakyow.app.response.status = 500
        Pakyow.app.router.handle!(500)

        if Configuration::Base.app.errors_in_browser
          Pakyow.app.response.body = []
          Pakyow.app.response.body << "<h4>#{CGI.escapeHTML(error.to_s)}</h4>"
          Pakyow.app.response.body << error.backtrace.join("<br />")
        end

        begin
          # caught by other middleware (e.g. logger)
          throw :error, error
        rescue ArgumentError
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pakyow-core-0.8rc1 pakyow-core/lib/core/middleware/router.rb