Class: BitWallet::HandlesError

Inherits:
Object
  • Object
show all
Defined in:
lib/bit_wallet/handles_error.rb

Class Method Summary collapse

Class Method Details

.from(message) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/bit_wallet/handles_error.rb', line 4

def self.from(message)
  error = if message.include?("-6")
    InsufficientFunds.new("cannot send an amount more than what this account has")
          elsif message.include?("-3")
            InvalidAmount.new("amount is invalid")
          elsif message.include?("-5")
            InvalidAddress.new("bitcoin address is invalid")
  else
    ArgumentError.new("unknown error: #{message}")
  end
  fail error if error
end