Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Rescue NET_HTTP_EXCEPTIONS when relaying message to Faye

* Rescue exceptions
* Provide overrideable hook Observer #handle_net_http_exceptions
* By default, log to Rails logger
  • Loading branch information...
commit cbe6598dc8ae78edb4c5d06b9871155b6185103d 1 parent 5c7b375
@jasonm jasonm authored
View
11 lib/backbone_sync-rails.rb
@@ -1,6 +1,13 @@
require 'backbone_sync-rails/faye'
-module BackboneSyncRails
- class Engine < ::Rails::Engine
+module BackboneSync
+ module Rails
+ NET_HTTP_EXCEPTIONS = [Timeout::Error, Errno::ETIMEDOUT, Errno::EINVAL,
+ Errno::ECONNRESET, Errno::ECONNREFUSED, EOFError,
+ Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError,
+ Net::ProtocolError]
+
+ class Engine < ::Rails::Engine
+ end
end
end
View
27 lib/backbone_sync-rails/faye/observer.rb
@@ -5,15 +5,36 @@ module Rails
module Faye
module Observer
def after_update(model)
- Event.new(model, :update).broadcast
+ begin
+ Event.new(model, :update).broadcast
+ rescue *NET_HTTP_EXCEPTIONS => e
+ handle_net_http_exception(e)
+ end
end
def after_create(model)
- Event.new(model, :create).broadcast
+ begin
+ Event.new(model, :create).broadcast
+ rescue *NET_HTTP_EXCEPTIONS => e
+ handle_net_http_exception(e)
+ end
end
def after_destroy(model)
- Event.new(model, :destroy).broadcast
+ begin
+ Event.new(model, :destroy).broadcast
+ rescue *NET_HTTP_EXCEPTIONS => e
+ handle_net_http_exception(e)
+ end
+ end
+
+ def handle_net_http_exception(exception)
+ ::Rails.logger.error("")
+ ::Rails.logger.error("Backbone::Sync::Rails::Faye::Observer encountered an exception:")
+ ::Rails.logger.error(exception.class.name)
+ ::Rails.logger.error(exception.message)
+ ::Rails.logger.error(exception.backtrace.join("\n"))
+ ::Rails.logger.error("")
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.