Sha256: cf81da6a70669f6cc560421d6a8463253235c49e87950f12d44ed5a5a6cfc58d

Contents?: true

Size: 855 Bytes

Versions: 16

Compression:

Stored size: 855 Bytes

Contents

require 'pundit'
module ErrorHandlers
  def self.included(m)
    m.rescue_from ActiveRecord::RecordInvalid do |e|
      error_response message: e.record.errors.to_a.uniq.join(', '), status: 400
    end

    m.rescue_from Grape::Exceptions::ValidationErrors do |e|
      error_response message: e.message, status: 400
    end

    m.rescue_from ActiveRecord::RecordNotFound do |e|
      error_response message: "Record not found! #{e.message}", status: 404
    end

    m.rescue_from ActiveRecord::InvalidForeignKey do |e|
      error_response message: "Join record not found! #{e.message}", status: 404
    end

    m.rescue_from Pundit::NotAuthorizedError do
      error_response message: "Forbidden", status: 403
    end

    m.rescue_from Pundit::NotDefinedError do
      error_response message: "Policy not implemented", status: 501
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
introspective_grape-0.6.1 spec/dummy/app/api/error_handlers.rb
introspective_grape-0.5.7 spec/dummy/app/api/error_handlers.rb
introspective_grape-0.5.6 spec/dummy/app/api/error_handlers.rb
introspective_grape-0.5.5 spec/dummy/app/api/error_handlers.rb
introspective_grape-0.5.4 spec/dummy/app/api/error_handlers.rb
introspective_grape-0.5.2 spec/dummy/app/api/error_handlers.rb
introspective_grape-0.5.0 spec/dummy/app/api/error_handlers.rb
introspective_grape-0.4.3 spec/dummy/app/api/error_handlers.rb
introspective_grape-0.4.2 spec/dummy/app/api/error_handlers.rb
introspective_grape-0.4.1 spec/dummy/app/api/error_handlers.rb
introspective_grape-0.4.0 spec/dummy/app/api/error_handlers.rb
introspective_grape-0.3.9 spec/dummy/app/api/error_handlers.rb
introspective_grape-0.3.7 spec/dummy/app/api/error_handlers.rb
introspective_grape-0.3.6 spec/dummy/app/api/error_handlers.rb
introspective_grape-0.3.5 spec/dummy/app/api/error_handlers.rb
introspective_grape-0.3.3 spec/dummy/app/api/error_handlers.rb