Module: Mumuki::Laboratory::Controllers::DynamicErrors
- Extended by:
- ActiveSupport::Concern
- Included in:
- Api::BaseController, ApplicationController
- Defined in:
- lib/mumuki/laboratory/controllers/dynamic_errors.rb
Instance Method Summary collapse
- #bad_record(exception) ⇒ Object
- #blocked_forum ⇒ Object
- #disabled ⇒ Object
- #disabled_organization ⇒ Object
- #forbidden ⇒ Object
- #gone ⇒ Object
- #internal_server_error(exception) ⇒ Object
- #not_found ⇒ Object
- #render_error(template, status, options = {}) ⇒ Object
- #unauthorized(exception) ⇒ Object
- #unprepared_organization ⇒ Object
Instance Method Details
#bad_record(exception) ⇒ Object
23 24 25 26 |
# 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 ⇒ Object
51 52 53 |
# File 'lib/mumuki/laboratory/controllers/dynamic_errors.rb', line 51 def blocked_forum render_error 'forbidden', 403, locals: { error_code: :blocked_forum, explanation: :blocked_forum_explanation } end |
#disabled ⇒ Object
47 48 49 |
# File 'lib/mumuki/laboratory/controllers/dynamic_errors.rb', line 47 def disabled render_error 'forbidden', 403, locals: { error_code: :disabled, explanation: :disabled_explanation } end |
#disabled_organization ⇒ Object
63 64 65 |
# File 'lib/mumuki/laboratory/controllers/dynamic_errors.rb', line 63 def disabled_organization render_error 'gone', 410, locals: { error_code: :disabled_organization, explanation: :disabled_organization_explanation } end |
#forbidden ⇒ Object
41 42 43 44 45 |
# File 'lib/mumuki/laboratory/controllers/dynamic_errors.rb', line 41 def forbidden = "The operation on organization #{Organization.current} was forbidden to user #{current_user.uid} with permissions #{current_user.}" Rails.logger.info render_error 'forbidden', 403, locals: { error_code: :forbidden, explanation: :forbidden_explanation }, error_message: end |
#gone ⇒ Object
55 56 57 |
# File 'lib/mumuki/laboratory/controllers/dynamic_errors.rb', line 55 def gone render_error 'gone', 410, locals: { error_code: :gone, explanation: :gone_explanation } end |
#internal_server_error(exception) ⇒ Object
32 33 34 35 |
# 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 ⇒ Object
28 29 30 |
# 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 = {}) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/mumuki/laboratory/controllers/dynamic_errors.rb', line 67 def render_error(template, status, ={}) if Mumukit::Platform.organization_mapping.path_under_namespace? Mumukit::Platform.current_organization_name, request.path, 'api' render_api_errors [[:error_message] || template.gsub('_', ' ')], status else render_app_errors template, .merge(status: status).except(:error_message) end end |
#unauthorized(exception) ⇒ Object
37 38 39 |
# File 'lib/mumuki/laboratory/controllers/dynamic_errors.rb', line 37 def (exception) render_error 'unauthorized', 401, error_message: exception. end |
#unprepared_organization ⇒ Object
59 60 61 |
# File 'lib/mumuki/laboratory/controllers/dynamic_errors.rb', line 59 def unprepared_organization render_error 'forbidden', 403, locals: { error_code: :unprepared_organization, explanation: :unprepared_organization_explanation } end |