Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes TypeError caused by attempts to Base64 encode nil @api_key values #672

Merged
merged 2 commits into from
Mar 29, 2021

Conversation

alexfulsome
Copy link
Contributor

When a Client is initialized with a nil api_key value (a Dotenv loading issue in my case), requests fail with an opaque TypeError when #set_headers tries to base64 encode it:

[2] Pry(main)> subscriptions.first
TypeError: no implicit conversion of nil into String
from /usr/local/var/rbenv/versions/2.5.7/lib/ruby/2.5.0/base64.rb:39:in `pack'

This explicitly casts @api_key to a string, which makes a blank value raise a Recurly::Errors::UnauthorizedError instead.

@douglasmiller
Copy link
Contributor

Good catch, @alexfulsome.

Let's try to save a trip to the API and add something like raise ArgumentError, "'api_key' must be set to a non-nil value" if api_key.nil? to the initializer prior to calling set_api_key

@douglasmiller douglasmiller self-assigned this Mar 15, 2021
@douglasmiller douglasmiller self-requested a review March 15, 2021 16:07
@douglasmiller douglasmiller added the V4 v2021-02-25 Client label Mar 15, 2021
Copy link
Contributor

@douglasmiller douglasmiller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@douglasmiller douglasmiller merged commit a4bc826 into recurly:master Mar 29, 2021
recurly-integrations pushed a commit that referenced this pull request Apr 14, 2021
[Full Changelog](4.0.1...4.1.0)

**Merged Pull Requests**

- Generated Latest Changes for v2021-02-25 (Backup Payment Method) [#691](#691) ([recurly-integrations](https://github.com/recurly-integrations))
- Generated Latest Changes for v2021-02-25 [#687](#687) ([recurly-integrations](https://github.com/recurly-integrations))
- Restoring NetworkError and it's derivatives [#685](#685) ([douglasmiller](https://github.com/douglasmiller))
- Generated Latest Changes for v2021-02-25 (Usage Percentage on Tiers) [#683](#683) ([recurly-integrations](https://github.com/recurly-integrations))
- Fixes TypeError caused by attempts to Base64 encode nil @api_key values [#672](#672) ([alexfulsome](https://github.com/alexfulsome))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
V4 v2021-02-25 Client
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants