Sha256: 4c56292d3751627b06cd1cbc6c96d7effa7c4d232077a8347a2102a29eb42181

Contents?: true

Size: 918 Bytes

Versions: 5

Compression:

Stored size: 918 Bytes

Contents

# coding: UTF-8

module Rescue
  module Controller
    module Dynamic

      def self.included(base)
        base.class_eval do
          define_method Rescue.config.respond_name do |code, exception = nil|
            e = {}
            if e.is_a? Rescue::ApplicationError
              e = { code: e.code, status: e.status, message: e.message }
            else
              e[:code]    = code
              e[:status]  = Rack::Utils::HTTP_STATUS_CODES[code]
              e[:message] = exception.message if exception
            end
  
            respond_to do |format|
              format.html { render status: code, template: "/errors/#{code}" }
              format.json { render status: code, json: { errors: [e] } }
              format.xml  { render status: code, xml:  { errors: [e] } }
            end
          end
        end
        base.send(:include, Rescue::Controller)
      end

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rescue-dog-0.3.9 lib/rescue/controllers/dynamic.rb
rescue-dog-0.3.8 lib/rescue/controllers/dynamic.rb
rescue-dog-0.3.7 lib/rescue/controllers/dynamic.rb
rescue-dog-0.3.5 lib/rescue/controllers/dynamic.rb
rescue-dog-0.3.4 lib/rescue/controllers/dynamic.rb