Sha256: 73124a36bc4b1a834ed0d5027b9ceb57ae7dcbaa4b602376d2e444983d507574

Contents?: true

Size: 657 Bytes

Versions: 5

Compression:

Stored size: 657 Bytes

Contents

# frozen_string_literal: true

module Mihari
  module Concerns
    #
    # Error unwrappable concern
    #
    module ErrorUnwrappable
      extend ActiveSupport::Concern

      def unwrap_error(err)
        return err unless err.is_a?(Dry::Monads::UnwrapError)

        # NOTE: UnwrapError's receiver can be either of:
        #       - Dry::Monads::Try::Error
        #       - Dry::Monads::Result::Failure
        receiver = err.receiver
        case receiver
        when Dry::Monads::Try::Error
          receiver.exception
        when Dry::Monads::Failure
          receiver.failure
        else
          err
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mihari-7.0.4 lib/mihari/concerns/error_unwrappable.rb
mihari-7.0.3 lib/mihari/concerns/error_unwrappable.rb
mihari-7.0.2 lib/mihari/concerns/error_unwrappable.rb
mihari-7.0.1 lib/mihari/concerns/error_unwrappable.rb
mihari-7.0.0 lib/mihari/concerns/error_unwrappable.rb