Skip to content

Instantly share code, notes, and snippets.

@phlegx
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phlegx/0c65ba2487b1bbf7a995 to your computer and use it in GitHub Desktop.
Save phlegx/0c65ba2487b1bbf7a995 to your computer and use it in GitHub Desktop.
Websocket-Rails Rescue
MyController < WebsocketRails::BaseController
include ActionController::Rescue
rescue_from ActiveRecord::RecordNotFound, with: :not_found_error
def not_found_error(exception)
# do something here
end
end
[Dispatcher] NoMethodError: private method `process_action' called for #<MyController:0x000000021e5fd0>
[Dispatcher] /home/linux/my_app/vendor/gems/websocket-rails/lib/websocket_rails/base_controller.rb:193:in `method_missing'
[Dispatcher] /home/linux/my_app/vendor/gems/websocket-rails/lib/websocket_rails/dispatcher.rb:67:in `block (3 levels) in route'
[Dispatcher] /home/linux/my_app/vendor/gems/websocket-rails/lib/websocket_rails/logging.rb:66:in `call'
[Dispatcher] /home/linux/my_app/vendor/gems/websocket-rails/lib/websocket_rails/logging.rb:66:in `log_event'
[Dispatcher] /home/linux/my_app/vendor/gems/websocket-rails/lib/websocket_rails/dispatcher.rb:64:in `block (2 levels) in route'
module Concerns
module WebsocketExceptionHandler
extend ActiveSupport::Concern
include ActiveSupport::Rescuable
included do
rescue_from ActiveRecord::RecordNotFound, with: :not_found_error
end
def not_found_error(exception = nil)
# do something here
end
# NOTE: The following methods are from include ActionController::Rescue
# See actionpack/lib/action_controller/metal/rescue.rb
def rescue_with_handler(exception)
if (exception.respond_to?(:original_exception) &&
(orig_exception = exception.original_exception) &&
handler_for_rescue(orig_exception))
exception = orig_exception
end
super(exception)
end
def show_detailed_exceptions?
false
end
# NOTE: Removed private declaration to work with websocket-rails.
def process_action(*args)
super
rescue Exception => exception
request.env['action_dispatch.show_detailed_exceptions'] ||= show_detailed_exceptions?
rescue_with_handler(exception) || raise(exception)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment