Sha256: 8330cbf0736a975c5bbba8855440aa1ba8537e7fddd98d9eca063ad6de2f5de4

Contents?: true

Size: 928 Bytes

Versions: 8

Compression:

Stored size: 928 Bytes

Contents

module Endow
  module ErrorHandling

  protected

    def retryable_errors
      graceful_errors
    end

    def graceful_error_for( error )
      if ( graceful_error = graceful_errors_map[error])
        return graceful_error
      end

      graceful_errors_map.each do |klass, graceful_error|
        return graceful_error if error.kind_of?( klass )
      end

      raise "Unexpected problem while attempting graceful handling of error: #{error.class.name} #{error.message}"
    end

    def graceful_errors
      graceful_errors_map.keys
    end

    def graceful_errors_map
      raise NotImplementedError
    end

    def with_graceful_error_handling( &block )
      block.call
    rescue *graceful_errors => e
      graceful_error = graceful_error_for( e )
      msg = "#{self.class.name}: #{graceful_error[:msg]}"
      log_graceful_error( msg )
      raise graceful_error[:klass], msg, e.backtrace
    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
endow-1.2.1 lib/endow/error_handling.rb
endow-1.2.0 lib/endow/error_handling.rb
endow-1.1.0 lib/endow/error_handling.rb
endow-1.0.1 lib/endow/error_handling.rb
endow-1.0.0 lib/endow/error_handling.rb
endow-0.4.0 lib/endow/error_handling.rb
endow-0.3.0 lib/endow/error_handling.rb
endow-0.2.0 lib/endow/error_handling.rb