Even if I can catch the exception raised from @ post.save and log the error and print the threads
begin if @post.save rescue Exception => ex
it still contains errors on the webpage and does not show any of my code in the stack trace. The Solr Sunspot model callback runs in a separate thread.
rsolr (1.0.9) lib/rsolr/connection.rb:19:in `rescue in execute' rsolr (1.0.9) lib/rsolr/connection.rb:14:in `execute' ... sunspot_rails (2.1.0) lib/sunspot/rails/solr_instrumentation.rb:15:in `send_and_receive_with_as_instrumentation' (eval):2:in `post' rsolr (1.0.9) lib/rsolr/client.rb:67:in `update' ... /usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service' /usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run' /usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
Pay attention to block in start_thread
?
So how can I catch this exception and show the user an error? I don't think the whole application should crash just because Solr is down.
I found this, http://makandracards.com/makandra/5273-using-solr-with-sunspot , but it only describes how to catch search exceptions, not index / update exceptions.
source share