lib/atol/transaction/get_token.rb in atol-0.5.0 vs lib/atol/transaction/get_token.rb in atol-0.5.1

- old
+ new

@@ -1,5 +1,7 @@ +# frozen_string_literal: true + require 'atol/request/get_token' require 'atol/errors' module Atol module Transaction @@ -8,31 +10,27 @@ @config = config || Atol.config raise(Atol::ConfigExpectedError) unless @config.is_a?(Atol::Config) end def call - @config.req_tries_number.times do |i| + @config.req_tries_number.times do request = Atol::Request::GetToken.new(config: @config) response = request.call - encoded_body = response.body.encode(Atol::ENCODING) + encoded_body = response.body.dup.force_encoding(Atol::ENCODING) json = JSON.parse(encoded_body) case response.code when '200' return json['token'] when '400' - case json['code'] - when 19 - raise Atol::AuthUserOrPasswordError - when 17 - raise Atol::AuthBadRequestError - end + raise Atol::AuthBadRequestError + when '401' + raise Atol::AuthUserOrPasswordError when '500' next end + raise "#{response.code} #{response.body}" end - - raise "#{response.code} #{response.body}" end end end end