plaid / plaid-ruby

Ruby bindings for Plaid

Home Page:https://plaid.com/docs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exception raised when trying to inspect or get message from Plaid::ApiError

enriquez opened this issue · comments

We have some specs that simulate Plaid::ApiErrors by doing something like this

Plaid::ApiError.new(
  code: 400, response_body: {
    error_code: 'INVALID_WEBHOOK_VERIFICATION_KEY_ID',
    error_type: 'INVALID_INPUT'
  }.to_json
)

The problem is when we try to rescue and read the message

rescue Plaid::ApiError => e
  puts e.message
end

An exception is raised

output error: #<NoMethodError: undefined method `+' for {:code=>400, :response_body=>"{\"error_code\":\"INVALID_WEBHOOK_VERIFICATION_KEY_ID\",\"error_type\":\"INVALID_INPUT\"}"}:Hash>

I expect a friendly message instead

"Error message: the server returns an error\nHTTP status code: 400\nResponse body: {\"error_code\":\"INVALID_WEBHOOK_VERIFICATION_KEY_ID\",\"error_type\":\"INVALID_INPUT\"}"

Something changed between v23 and v24 here which is causing the new exception:
https://github.com/plaid/plaid-ruby/blame/80cde7efe279d18e50fe14366be388bec0d3cf53/lib/plaid/api_error.rb#L28C9-L28C9

commented

Oh how embarrassing -- it looks like this was introduced in 24.1.0 where we went to ruby 6.3. It looks like, when upgrading the template generator, I accidentally edited the wrong line of the template file, and apparently we don't have any tests that would catch this. I have a PR in progress that should fix the issue in the next clib release. Thank you for the report!

commented

@enriquez in the mean time, would it be possible for you to try moving the line "@message = arg" from line 28 to right after line 35 in the api_error.rb file and let us know if that fixes the issue for you?

We are encountering the same error, rolling back to version 23 for now until the fix is released. Thanks for your work here!

commented

@enriquez in the mean time, would it be possible for you to try moving the line "@message = arg" from line 28 to right after line 35 in the api_error.rb file and let us know if that fixes the issue for you?

@phoenixy1 I stumbled upon this issue and your suggestion fixed the issue for me. I'm able to inspect the error without the undefined method + error

commented

This should now be fixed with today's release. Please comment if it is still happening after upgrading!