Sha256: f98575a65e08314289bc7ca24ff389d2a4f3f571e1a757e4d0562b0801b3ac1a

Contents?: true

Size: 1.04 KB

Versions: 15

Compression:

Stored size: 1.04 KB

Contents

module GrapeApeRails
  module Handlers
    module Responses
      extend ActiveSupport::Concern

      included do
        format :json
        formatter :json, Grape::Formatter::GarRabl
        error_formatter :json, Grape::Formatter::GarError

        before do
          # ...
        end

        rescue_from Grape::Exceptions::ValidationErrors do |e|
          status = 422
          hash_err = { error: {
            code: 'RESOURCE_FAILED_VALIDATION',
            message: '[RESOURCE_FAILED_VALIDATION] Resource failed validation per API parameter requirements' }
          }
          log_msg = hash_err[:error].clone
          hash_err[:error].merge!({ data: e.errors }) if e.errors.present?
          if defined?(::Rails) && Rails.respond_to?(:logger)
            api_version = "[#{env['rack.routing_args'][:route_info].route_version}]" rescue nil
            Rails.logger.warn "[API]#{api_version} Responding with #{status} #{log_msg}"
          end
          Rack::Response.new(MultiJson.dump(hash_err), status)
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
grape_ape_rails-0.9.13 lib/grape_ape_rails/handlers/responses.rb
grape_ape_rails-0.9.12 lib/grape_ape_rails/handlers/responses.rb
grape_ape_rails-0.9.11 lib/grape_ape_rails/handlers/responses.rb
grape_ape_rails-0.9.10 lib/grape_ape_rails/handlers/responses.rb
grape_ape_rails-0.9.9 lib/grape_ape_rails/handlers/responses.rb
grape_ape_rails-0.9.8 lib/grape_ape_rails/handlers/responses.rb
grape_ape_rails-0.9.7 lib/grape_ape_rails/handlers/responses.rb
grape_ape_rails-0.9.6 lib/grape_ape_rails/handlers/responses.rb
grape_ape_rails-0.9.5 lib/grape_ape_rails/handlers/responses.rb
grape_ape_rails-0.9.4 lib/grape_ape_rails/handlers/responses.rb
grape_ape_rails-0.9.3 lib/grape_ape_rails/handlers/responses.rb
grape_ape_rails-0.9.2 lib/grape_ape_rails/handlers/responses.rb
grape_ape_rails-0.9.1 lib/grape_ape_rails/handlers/responses.rb
grape_ape_rails-0.5.1 lib/grape_ape_rails/handlers/responses.rb
grape_ape_rails-0.5.0 lib/grape_ape_rails/handlers/responses.rb