lib/credit_gateway/client.rb in credit_gateway-0.1.0 vs lib/credit_gateway/client.rb in credit_gateway-0.1.1
- old
+ new
@@ -2,10 +2,11 @@
require 'faraday'
require 'faraday_middleware/multi_json'
require 'credit_gateway/configuration'
require 'credit_gateway/faraday_auth'
+require 'credit_gateway/errors'
module CreditGateway
class Client
def initialize
return if Faraday::Request.fetch_middleware(:credit_gateway_auth)
@@ -45,10 +46,14 @@
def handle_response(response)
return if response.success?
case response.status
when 400
- raise InvalidRequestError, response.body
+ if response.body.dig(:Errors, 0, :ErrorCode) == 'Company.NotFound'
+ raise CompanyNotFoundError, response.body.dig(:Errors, 0, :ErrorMessage)
+ else
+ raise InvalidRequestError, response.body
+ end
when 401
raise UnauthorizedError, response.body
when 404
raise NotFoundError, response.body
else