Class: Response::RaiseMtGoxError

Inherits:
Middleware
  • Object
show all
Defined in:
lib/faraday/response/raise_mtgox_error.rb

Instance Method Summary collapse

Instance Method Details

#on_complete(env) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/faraday/response/raise_mtgox_error.rb', line 6

def on_complete(env)
  if 200 == env[:status] && 'MySQL error, please retry later' == env[:body]
    raise MtGox::MysqlError, "MySQL error, please retry later"
  elsif 403 == env[:status] && JSON.load(env[:body])["result"] == "error"
    raise MtGox::UnauthorizedError, JSON.load(env[:body])["error"]
  elsif 404 != env[:status] && JSON.load(env[:body])["result"] == "error"
    raise MtGox::Error, JSON.load(env[:body])["error"]
  end
end