Skip to content

Instantly share code, notes, and snippets.

@nz
Created December 30, 2010 20:59
Show Gist options
  • Save nz/760294 to your computer and use it in GitHub Desktop.
Save nz/760294 to your computer and use it in GitHub Desktop.
Silently fail instead of raising an exception when an error occurs while writing to Solr.
###
#
# Custom write failure handling when there is an error writing to Solr.
# Install this in an initializer.
# Prints error messages to stderr.
#
# NOTE: does not fail for reads; you should catch those exceptions in your controller.
#
##
Sunspot.session = Sunspot::SessionProxy::SilentFailSessionProxy.new(Sunspot.session)
###
#
# Silently fail instead of raising an exception when an error occurs while writing to Solr.
# Install this in an initializer.
#
# NOTE: does not fail for reads; you should catch those exceptions in your controller.
#
##
class CustomSilentFailSessionProxy < Sunspot::SessionProxy::SilentFailSessionProxy
def rescued_exception(method_name, e)
# handle the exception, e, however you like!
end
end
Sunspot.session = CustomSilentFailSessionProxy.new(Sunspot.session)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment