module RapidApi::ActionController::Errors

Constants

NotAuthorizedError
NotFoundError

Public Instance Methods

not_authorized!() click to toggle source
# File lib/rapid_api/action_controller/errors.rb, line 26
def not_authorized!
  raise NotAuthorizedError
end
not_found!() click to toggle source
# File lib/rapid_api/action_controller/errors.rb, line 30
def not_found!
  raise NotFoundError
end
not_processable!(errors) click to toggle source
# File lib/rapid_api/action_controller/errors.rb, line 34
def not_processable!(errors)
  raise NotProcessableError.new(errors)
end

Protected Instance Methods

_not_authorized(e) click to toggle source
# File lib/rapid_api/action_controller/errors.rb, line 53
def _not_authorized(e)
  render_error_message 'Not Authorized', :unauthorized, e
end
_not_found(e) click to toggle source
# File lib/rapid_api/action_controller/errors.rb, line 57
def _not_found(e)
  render_error_message 'Not Found', :not_found, e
end
_not_processable(e) click to toggle source
# File lib/rapid_api/action_controller/errors.rb, line 61
def _not_processable(e)
  render json: e.errors, status: response_code_for(:unprocessable_entity)
end
_server_error(e) click to toggle source
# File lib/rapid_api/action_controller/errors.rb, line 65
def _server_error(e)
  render_error_message "Server Error: #{e.message}", :internal_server_error, e
end
log_error(e) click to toggle source
# File lib/rapid_api/action_controller/errors.rb, line 48
def log_error(e)
  puts e.message
  e.backtrace.map { |m| puts m }
end
render_error_message(message, status, e) click to toggle source
# File lib/rapid_api/action_controller/errors.rb, line 40
def render_error_message(message, status, e)
  render json: { errors: [message] }, status: response_code_for(status)
end
response_code_for(status) click to toggle source
# File lib/rapid_api/action_controller/errors.rb, line 44
def response_code_for(status)
  RapidApi.config.response_codes[status]
end