plaid / plaid-ruby

Ruby bindings for Plaid
https://plaid.com/docs
MIT License
225 stars 143 forks source link

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

Closed enriquez closed 8 months ago

enriquez commented 9 months ago

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

phoenixy1 commented 9 months ago

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!

phoenixy1 commented 9 months ago

@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?

marvs commented 9 months ago

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

pdx91 commented 9 months ago

@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

phoenixy1 commented 8 months ago

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