Fix: Plaid::ApiError (MAYBE-RAILS-DG) #1763
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The error "client is not authorized to access the following products: ["investments" "liabilities"]" occurs because the Plaid API client is attempting to request access to products that haven't been enabled for the client's account. The original code was designed to automatically request additional products beyond the primary product needed, likely to provide a smoother user experience by pre-emptively getting access to all potentially useful products.
The issue stems from the
get_additional_consented_products
method which was returning all supported products minus the primary product, regardless of what the client was actually authorized to use. This approach, while convenient for fully-authorized clients, fails when the client doesn't have access to all products.Key changes made:
additional_consented_products
parameter from the link token request to ensure we only request the primary product needed.MAYBE_SUPPORTED_PLAID_PRODUCTS
constant andget_additional_consented_products
method in place for future use if needed, but stopped using it in the link token request.This change maintains the core functionality while fixing the authorization error by:
I've also added a new test to verify this behavior:
This approach follows the principle of least privilege by only requesting access to necessary products rather than trying to get access to everything up front.
Error Details
Summary:
Stacktrace:
Tip
You can make revisions or ask questions of Revise.dev by using
/revise
in any comment or review!/revise Add a comment above the method to explain why we're making this change.
/revise Why did you choose to make this change specifically?
Important
If something doesn’t look right, click to retry this interaction.
Quick links: View in Sentry • View in Revise