Sha256: 263fcc1ea7bcd3a82a25aafc913cc2375ec0b937081bb2db08c84ddfd97c911b

Contents?: true

Size: 1.3 KB

Versions: 18

Compression:

Stored size: 1.3 KB

Contents

module Mumuki::Laboratory::Controllers::DynamicErrors
  extend ActiveSupport::Concern

  included do
    unless Rails.application.config.consider_all_requests_local
      rescue_from Exception, with: :internal_server_error
      rescue_from ActionController::RoutingError, with: :not_found
    end
    rescue_from ActiveRecord::RecordNotFound, with: :not_found
    rescue_from Mumukit::Auth::UnauthorizedAccessError, with: :forbidden
    rescue_from Mumuki::Laboratory::NotFoundError, with: :not_found
    rescue_from Mumuki::Laboratory::ForbiddenError, with: :forbidden
    rescue_from Mumuki::Laboratory::UnauthorizedError, with: :unauthorized
    rescue_from Mumuki::Laboratory::GoneError, with: :gone
  end

  def not_found
    render 'errors/not_found', status: 404
  end

  def internal_server_error(exception)
    Rails.logger.error "Internal server error: #{exception} \n#{exception.backtrace.join("\n")}"
    render 'errors/internal_server_error', status: 500
  end

  def unauthorized
    render 'errors/unauthorized', status: 401
  end

  def forbidden
    Rails.logger.info "Access to organization #{Organization.current} was forbidden to user #{current_user} with permissions #{current_user.permissions}"
    render 'errors/forbidden', status: 403
  end

  def gone
    render 'errors/gone', status: 410
  end

end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
mumuki-laboratory-5.3.0 lib/mumuki/laboratory/controllers/dynamic_errors.rb
mumuki-laboratory-5.2.1 lib/mumuki/laboratory/controllers/dynamic_errors.rb
mumuki-laboratory-5.2.0 lib/mumuki/laboratory/controllers/dynamic_errors.rb
mumuki-laboratory-5.1.1 lib/mumuki/laboratory/controllers/dynamic_errors.rb
mumuki-laboratory-5.1.0 lib/mumuki/laboratory/controllers/dynamic_errors.rb
mumuki-laboratory-5.0.12 lib/mumuki/laboratory/controllers/dynamic_errors.rb
mumuki-laboratory-5.0.11 lib/mumuki/laboratory/controllers/dynamic_errors.rb
mumuki-laboratory-5.0.10 lib/mumuki/laboratory/controllers/dynamic_errors.rb
mumuki-laboratory-5.0.9 lib/mumuki/laboratory/controllers/dynamic_errors.rb
mumuki-laboratory-5.0.8 lib/mumuki/laboratory/controllers/dynamic_errors.rb
mumuki-laboratory-5.0.7 lib/mumuki/laboratory/controllers/dynamic_errors.rb
mumuki-laboratory-5.0.6 lib/mumuki/laboratory/controllers/dynamic_errors.rb
mumuki-laboratory-5.0.5 lib/mumuki/laboratory/controllers/dynamic_errors.rb
mumuki-laboratory-5.0.4 lib/mumuki/laboratory/controllers/dynamic_errors.rb
mumuki-laboratory-5.0.3 lib/mumuki/laboratory/controllers/dynamic_errors.rb
mumuki-laboratory-5.0.2 lib/mumuki/laboratory/controllers/dynamic_errors.rb
mumuki-laboratory-5.0.1 lib/mumuki/laboratory/controllers/dynamic_errors.rb
mumuki-laboratory-5.0.0 lib/mumuki/laboratory/controllers/dynamic_errors.rb