Class: Upfluence::Utils::Thrift::Middleware::ErrorCatcher
- Inherits:
-
Object
- Object
- Upfluence::Utils::Thrift::Middleware::ErrorCatcher
- Defined in:
- lib/upfluence/utils/thrift/middleware/error_catcher.rb
Constant Summary collapse
- STANDARD_THRIFT_EXCEPTIONS =
[ ::Thrift::ApplicationException, ::Thrift::TransportException, ::Thrift::ProtocolException ].freeze
Instance Method Summary collapse
-
#initialize(app, error_logger) ⇒ ErrorCatcher
constructor
A new instance of ErrorCatcher.
- #method_missing(method, *args, &block) ⇒ Object
Constructor Details
#initialize(app, error_logger) ⇒ ErrorCatcher
Returns a new instance of ErrorCatcher.
12 13 14 15 |
# File 'lib/upfluence/utils/thrift/middleware/error_catcher.rb', line 12 def initialize(app, error_logger) @app = app @error_logger = error_logger end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/upfluence/utils/thrift/middleware/error_catcher.rb', line 17 def method_missing(method, *args, &block) @app.send(method, *args, &block) rescue ::Thrift::Exception => e if STANDARD_THRIFT_EXCEPTIONS.include? e.class @error_logger.notify(e, method, *args) end raise e rescue => e @error_logger.notify(e, method, *args) raise ::Thrift::ApplicationException.new( ::Thrift::ApplicationException::INTERNAL_ERROR, e.to_s ) end |