module Mumuki::Laboratory::Controllers::DynamicErrors

Public Instance Methods

bad_record(exception) click to toggle source
# File lib/mumuki/laboratory/controllers/dynamic_errors.rb, line 23
def bad_record(exception)
  # bad records can only be produced thourgh API
  render_api_errors exception.record.errors, 400
end
blocked_forum() click to toggle source
# File lib/mumuki/laboratory/controllers/dynamic_errors.rb, line 51
def blocked_forum
  render_error 'forbidden', 403, locals: { explanation: :blocked_forum_explanation }
end
disabled() click to toggle source
# File lib/mumuki/laboratory/controllers/dynamic_errors.rb, line 47
def disabled
  render_error 'forbidden', 403, locals: { explanation: :disabled_explanation }
end
disabled_organization() click to toggle source
# File lib/mumuki/laboratory/controllers/dynamic_errors.rb, line 63
def disabled_organization
  render_error 'gone', 410, locals: { explanation: :disabled_organization_explanation }
end
forbidden() click to toggle source
# File lib/mumuki/laboratory/controllers/dynamic_errors.rb, line 41
def forbidden
  message = "The operation on organization #{Organization.current} was forbidden to user #{current_user.uid} with permissions #{current_user.permissions}"
  Rails.logger.info message
  render_error 'forbidden', 403, locals: { explanation: :forbidden_explanation }, error_message: message
end
gone() click to toggle source
# File lib/mumuki/laboratory/controllers/dynamic_errors.rb, line 55
def gone
  render_error 'gone', 410, locals: { explanation: :gone_explanation }
end
internal_server_error(exception) click to toggle source
# File lib/mumuki/laboratory/controllers/dynamic_errors.rb, line 32
def internal_server_error(exception)
  Rails.logger.error "Internal server error: #{exception} \n#{exception.backtrace.join("\n")}"
  render_error 'internal_server_error', 500
end
not_found() click to toggle source
# File lib/mumuki/laboratory/controllers/dynamic_errors.rb, line 28
def not_found
  render_error 'not_found', 404, formats: [:html]
end
render_error(template, status, options={}) click to toggle source
# File lib/mumuki/laboratory/controllers/dynamic_errors.rb, line 67
def render_error(template, status, options={})
  if Mumukit::Platform.organization_mapping.path_under_namespace? Mumukit::Platform.current_organization_name, request.path, 'api'
    render_api_errors [options[:error_message] || template.gsub('_', ' ')], status
  else
    render_app_errors template, options.merge(status: status).except(:error_message)
  end
end
unauthorized(exception) click to toggle source
# File lib/mumuki/laboratory/controllers/dynamic_errors.rb, line 37
def unauthorized(exception)
  render_error 'unauthorized', 401, error_message: exception.message
end
unprepared_organization() click to toggle source
# File lib/mumuki/laboratory/controllers/dynamic_errors.rb, line 59
def unprepared_organization
  render_error 'forbidden', 403, locals: { explanation: :unprepared_organization_explanation }
end

Private Instance Methods

render_api_errors(errors, status) click to toggle source
# File lib/mumuki/laboratory/controllers/dynamic_errors.rb, line 81
def render_api_errors(errors, status)
  render json: { errors: errors }, status: status
end
render_app_errors(template, options) click to toggle source
# File lib/mumuki/laboratory/controllers/dynamic_errors.rb, line 77
def render_app_errors(template, options)
  render "errors/#{template}", options
end