Module: Mixins::ErrorHandling

Included in:
ApplicationController
Defined in:
app/controllers/mixins/error_handling.rb

Overview

A set of error handling methods responding to various errors raised by the server and its backends. These are designed to work with the `rescue_from` method.

Instance Method Summary collapse

Instance Method Details

#handle_auth_err(exception) ⇒ Object

Handler responding with HTTP 401 and the exception message.


76
77
78
79
# File 'app/controllers/mixins/error_handling.rb', line 76

def handle_auth_err(exception)
  logger.warn "[Backend] Failed to authenticate user: #{exception.message}"
  render text: exception.message, status: 401
end

#handle_authz_err(exception) ⇒ Object

Handler responding with HTTP 403 and the exception message.


84
85
86
87
# File 'app/controllers/mixins/error_handling.rb', line 84

def handle_authz_err(exception)
  logger.warn "[Backend] Failed to authorize user: #{exception.message}"
  render text: exception.message, status: 403
end

#handle_backend_unavailable_err(exception) ⇒ Object

Handler responding with HTTP 503 and the exception message.


68
69
70
71
# File 'app/controllers/mixins/error_handling.rb', line 68

def handle_backend_unavailable_err(exception)
  logger.error "[Backend] Failed to connect to the underlying CMF: #{exception.message}"
  render text: exception.message, status: 503
end

#handle_internal_backend_err(exception) ⇒ Object

Handler responding with HTTP 500 and the exception message.


60
61
62
63
# File 'app/controllers/mixins/error_handling.rb', line 60

def handle_internal_backend_err(exception)
  logger.error "[Backend] Failed to execute a backend routine: #{exception.message}"
  render text: exception.message, status: 500
end

#handle_invalid_resource_err(exception) ⇒ Object

Handler responding with HTTP 409 and the exception message.


44
45
46
47
# File 'app/controllers/mixins/error_handling.rb', line 44

def handle_invalid_resource_err(exception)
  logger.warn "[Backend] User did not provide a valid resource instance: #{exception.message}"
  render text: exception.message, status: 409
end

#handle_not_impl_err(exception) ⇒ Object

Handler responding with HTTP 501 and the exception message.


28
29
30
31
# File 'app/controllers/mixins/error_handling.rb', line 28

def handle_not_impl_err(exception)
  logger.error "[Backend] Active backend does not implement requested method: #{exception.message}"
  render text: exception.message, status: 501
end

#handle_parser_input_err(exception) ⇒ Object

Handler responding with HTTP 400 and the exception message.


20
21
22
23
# File 'app/controllers/mixins/error_handling.rb', line 20

def handle_parser_input_err(exception)
  logger.warn "[Parser] Request from #{request.remote_ip} refused with: #{exception.message}"
  render text: exception.message, status: 400
end

#handle_parser_type_err(exception) ⇒ Object

Handler responding with HTTP 406 and the exception message.


12
13
14
15
# File 'app/controllers/mixins/error_handling.rb', line 12

def handle_parser_type_err(exception)
  logger.warn "[Parser] Request from #{request.remote_ip} refused with: #{exception.message}"
  render text: exception.message, status: 406
end

#handle_resource_not_found_err(exception) ⇒ Object

Handler responding with HTTP 404 and the exception message.


52
53
54
55
# File 'app/controllers/mixins/error_handling.rb', line 52

def handle_resource_not_found_err(exception)
  logger.warn "[Backend] User referenced a non-existent resource instance: #{exception.message}"
  render text: exception.message, status: 404
end

#handle_wrong_args_err(exception) ⇒ Object

Handler responding with HTTP 400 and the exception message.


36
37
38
39
# File 'app/controllers/mixins/error_handling.rb', line 36

def handle_wrong_args_err(exception)
  logger.warn "[Backend] User did not provide necessary arguments to execute an action: #{exception.message}"
  render text: exception.message, status: 400
end