module Mixins::ErrorHandling

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.

Public Instance Methods

handle_auth_err(exception) click to toggle source

Handler responding with HTTP 401 and the exception message.

@param exception [Exception] exception to convert into a response

# File app/controllers/mixins/error_handling.rb, line 68
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) click to toggle source

Handler responding with HTTP 403 and the exception message.

@param exception [Exception] exception to convert into a response

# File app/controllers/mixins/error_handling.rb, line 76
def handle_authz_err(exception)
  logger.warn "[Backend] Failed to authorize user: #{exception.message}"
  render text: exception.message, status: 403
end
handle_internal_backend_err(exception) click to toggle source

Handler responding with HTTP 500 and the exception message.

@param exception [Exception] exception to convert into a response

# 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) click to toggle source

Handler responding with HTTP 409 and the exception message.

@param exception [Exception] exception to convert into a response

# 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) click to toggle source

Handler responding with HTTP 501 and the exception message.

@param exception [Exception] exception to convert into a response

# 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) click to toggle source

Handler responding with HTTP 400 and the exception message.

@param exception [Exception] exception to convert into a response

# 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) click to toggle source

Handler responding with HTTP 406 and the exception message.

@param exception [Exception] exception to convert into a response

# 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) click to toggle source

Handler responding with HTTP 404 and the exception message.

@param exception [Exception] exception to convert into a response

# 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) click to toggle source

Handler responding with HTTP 400 and the exception message.

@param exception [Exception] exception to convert into a response

# 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