Sha256: f71e178a06cda62bb4f29ea3fcec11086a35d7e34dd1158448f45df81d51011d

Contents?: true

Size: 1.22 KB

Versions: 52

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

module IbrainHandler
  extend ActiveSupport::Concern

  included do
    rescue_from StandardError, with: :standard_handler
    rescue_from ActionController::ParameterMissing, with: :parameter_handler
    rescue_from ActiveRecord::RecordNotFound, with: :not_found_handler
    rescue_from ActiveRecord::RecordInvalid, with: :bad_request_handler
    rescue_from IbrainErrors::PermissionError, with: :permission_denied_handler
    rescue_from IbrainErrors::UnknownError, with: :bad_request_handler
    rescue_from ActionController::InvalidAuthenticityToken, with: :unauthorized_handler
    rescue_from ActiveSupport::MessageVerifier::InvalidSignature, with: :unauthorized_handler
    rescue_from GraphQL::ExecutionError, with: :bad_request_handler
  end

  private

  def standard_handler(errors)
    render_json_error(errors, 500)
  end

  def bad_request_handler(errors)
    render_json_error(errors, 400)
  end

  def parameter_handler(errors)
    render_json_error(errors, 400)
  end

  def not_found_handler(errors)
    render_json_error(errors, 404)
  end

  def permission_denied_handler(errors)
    render_json_error(errors, 405)
  end

  def unauthorized_handler(errors)
    render_json_error(errors, 401)
  end
end

Version data entries

52 entries across 52 versions & 1 rubygems

Version Path
ibrain-core-0.5.15 app/controllers/concerns/ibrain_handler.rb
ibrain-core-0.5.13 app/controllers/concerns/ibrain_handler.rb
ibrain-core-0.5.12 app/controllers/concerns/ibrain_handler.rb
ibrain-core-0.5.10 app/controllers/concerns/ibrain_handler.rb
ibrain-core-0.5.9 app/controllers/concerns/ibrain_handler.rb
ibrain-core-0.5.8 app/controllers/concerns/ibrain_handler.rb
ibrain-core-0.5.7 app/controllers/concerns/ibrain_handler.rb
ibrain-core-0.5.6 app/controllers/concerns/ibrain_handler.rb
ibrain-core-0.5.5 app/controllers/concerns/ibrain_handler.rb
ibrain-core-0.5.4 app/controllers/concerns/ibrain_handler.rb
ibrain-core-0.5.3 app/controllers/concerns/ibrain_handler.rb
ibrain-core-0.5.2 app/controllers/concerns/ibrain_handler.rb
ibrain-core-0.5.1 app/controllers/concerns/ibrain_handler.rb
ibrain-core-0.5.0 app/controllers/concerns/ibrain_handler.rb
ibrain-core-0.4.9 app/controllers/concerns/ibrain_handler.rb
ibrain-core-0.4.8 app/controllers/concerns/ibrain_handler.rb
ibrain-core-0.4.7 app/controllers/concerns/ibrain_handler.rb
ibrain-core-0.4.6 app/controllers/concerns/ibrain_handler.rb
ibrain-core-0.4.5 app/controllers/concerns/ibrain_handler.rb
ibrain-core-0.4.4 app/controllers/concerns/ibrain_handler.rb