Skip to content

[Bug]: v11 unexpected TypeError for unsuccessful API requests #319

@danix9000

Description

@danix9000

Description

A TypeError is raised when the API responds with an unsuccessful response

Steps to reproduce

  1. Install the 'adyen-ruby-api-library'
gem install adyen-ruby-api-library -v 11.0
  1. open an irb console
irb
  1. require the gem
require 'adyen-ruby-api-library'
  1. Create a client instance with invalid credentials:
client = Adyen::Client.new(ws_user: 'foo', ws_password: 'bar', env: :test)
  1. Issue an authorise request
client.payment.payments_api.authorise({})

Actual behavior

A TypeError is raised, potentially indicating that the response body isn't being correctly parsed as JSON.

/Users/dani/.rvm/gems/ruby-3.2.2/gems/adyen-ruby-api-library-11.0.0/lib/adyen/client.rb:372:in `[]': no implicit conversion of Symbol into Integer (TypeError)

        message = error_details[:detail] || error_details[:message]
                                ^^^^^^^
	from /Users/dani/.rvm/gems/ruby-3.2.2/gems/adyen-ruby-api-library-11.0.0/lib/adyen/client.rb:372:in `build_error_message'
	from /Users/dani/.rvm/gems/ruby-3.2.2/gems/adyen-ruby-api-library-11.0.0/lib/adyen/client.rb:221:in `call_adyen_api'
	from /Users/dani/.rvm/gems/ruby-3.2.2/gems/adyen-ruby-api-library-11.0.0/lib/adyen/services/payment/payments_api.rb:22:in `authorise'
	from (irb):5:in `<main>'
	from /Users/dani/.rvm/gems/ruby-3.2.2/gems/irb-1.15.2/exe/irb:9:in `<top (required)>'
	from /Users/dani/.rvm/gems/ruby-3.2.2/bin/irb:25:in `load'
	from /Users/dani/.rvm/gems/ruby-3.2.2/bin/irb:25:in `<main>'
	from /Users/dani/.rvm/gems/ruby-3.2.2/bin/ruby_executable_hooks:22:in `eval'
	from /Users/dani/.rvm/gems/ruby-3.2.2/bin/ruby_executable_hooks:22:in `<main>'

Expected behavior

An appropriate Adyen::AuthenticationError should be raised.

Code snippet or screenshots (if applicable)

No response

Adyen Ruby API Library version

11.0.0

Ruby language version

3.2.2

Operating System

macOS

Additional context

Having skimmed the code I believe that the issue might be in a missing JSON.parse invoketion with the newly added Adyen::Client#build_error_message method.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions