Module: Serf::Util::ErrorHandling
- Includes:
- ProtectedCall
- Included in:
- Middleware::ErrorHandler
- Defined in:
- lib/serf/util/error_handling.rb
Overview
Helper module to rescues exceptions from executing blocks of code, and then converts the exception to an “Error Message”.
Instance Method Summary collapse
-
#handle_error(e) ⇒ Object
Including classes may override this method to do alternate error handling.
-
#with_error_handling(*args, &block) ⇒ Object
A block wrapper to handle errors when executing a block.
Methods included from ProtectedCall
Instance Method Details
#handle_error(e) ⇒ Object
Including classes may override this method to do alternate error handling. By default, this method will create a new error event message.
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/serf/util/error_handling.rb', line 27 def handle_error(e) # no error was passed, so do nothing. return nil unless e # Return a simple error event message return { error: e.class.to_s, message: e., process_env: ENV.to_hash, hostname: Socket.gethostname, backtrace: e.backtrace.join("\n") } end |
#with_error_handling(*args, &block) ⇒ Object
A block wrapper to handle errors when executing a block.
18 19 20 21 |
# File 'lib/serf/util/error_handling.rb', line 18 def with_error_handling(*args, &block) results, err = pcall *args, &block return results, handle_error(err) end |