Sha256: 3aac96032c847e900b4402823d179de6f4f26eaec77b63f3ad7a142793e5f5d8

Contents?: true

Size: 1.31 KB

Versions: 7

Compression:

Stored size: 1.31 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, formats: [:html]
  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

7 entries across 7 versions & 1 rubygems

Version Path
mumuki-laboratory-5.7.0 lib/mumuki/laboratory/controllers/dynamic_errors.rb
mumuki-laboratory-5.6.3 lib/mumuki/laboratory/controllers/dynamic_errors.rb
mumuki-laboratory-5.6.2 lib/mumuki/laboratory/controllers/dynamic_errors.rb
mumuki-laboratory-5.6.1 lib/mumuki/laboratory/controllers/dynamic_errors.rb
mumuki-laboratory-5.6.0 lib/mumuki/laboratory/controllers/dynamic_errors.rb
mumuki-laboratory-5.5.0 lib/mumuki/laboratory/controllers/dynamic_errors.rb
mumuki-laboratory-5.4.0 lib/mumuki/laboratory/controllers/dynamic_errors.rb