Last active
August 29, 2015 14:24
-
-
Save phlegx/0c65ba2487b1bbf7a995 to your computer and use it in GitHub Desktop.
Websocket-Rails Rescue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MyController < WebsocketRails::BaseController | |
include ActionController::Rescue | |
rescue_from ActiveRecord::RecordNotFound, with: :not_found_error | |
def not_found_error(exception) | |
# do something here | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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