Project

General

Profile

« Previous | Next » 

Revision 46338cd7

Added by Daniel Lobato Garcia over 10 years ago

fixes #3515 - API handles not found objects with 404

View differences:

app/controllers/api/base_controller.rb
end
rescue_from StandardError, :with => lambda { |error|
Rails.logger.error "#{error.message} (#{error.class})\n#{error.backtrace.join("\n")}"
logger.error "#{error.message} (#{error.class})\n#{error.backtrace.join("\n")}"
render_error 'standard_error', :status => 500, :locals => { :exception => error }
}
rescue_from Apipie::ParamError, :with => lambda { |error|
Rails.logger.info "#{error.message} (#{error.class})"
logger.info "#{error.message} (#{error.class})"
render_error 'param_error', :status => :bad_request, :locals => { :exception => error }
}
rescue_from ActiveRecord::RecordNotFound, :with => lambda { |error|
logger.info "#{error.message} (#{error.class})"
not_found(:message => "#{error.message}", :class => "#{error.class}")
}
def get_resource
instance_variable_get :"@#{resource_name}" or raise 'no resource loaded'
end
......
protected
def not_found
render_error 'not_found', :status => :not_found and return false
def not_found(options = nil)
not_found_message = {}
case options
when String
not_found_message.merge! :message => options
when Hash
not_found_message.merge! options
else
render_error 'not_found', :status => :not_found and return false
end
render :json => not_found_message, :status => :not_found and return false
end
def process_resource_error(options = { })
......
def not_found_if_nested_id_exists
allowed_nested_id.each do |obj_id|
if params[obj_id].present?
msg = "#{obj_id.humanize} not found by id '#{params[obj_id]}'"
render :json => {:message => msg}, :status => :not_found and return false
not_found "#{obj_id.humanize} not found by id '#{params[obj_id]}'"
end
end
end

Also available in: Unified diff