fix: update metadata type to string #1408
Merged
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.
Reference
No JIRA ticket, based on Slack discussions
Summary
The
setRequestMetadataKey
function used to accept any object in the value parameter. The function is now modified to take in only a string or nil as Branch APIs cannot process non-string values for metadata.Motivation
The SDK exposes the
setRequestMetadataKey
function to allow developers to send in any value that can be attached with all event metadata. This includes IDs, custom parameters etc.As of today, the function takes in a string key with any value (string/bool/object/integer) without any errors. However, on passing a non-string value for metadata, one can observe that all Branch APIs start failing with a 400 error, citing invalid JSON. This is because the Branch APIs are designed to take in only string values for metadata. This can lead to confusion and difficulty in debugging the issue because it is not immediately apparent that the issue is caused because of a non-string metadata value.
This PR aims to eliminate this confusion by updating the signature of the
setRequestMetadataKey
function to accept only string or nil values (nil is accepted so that the value can be unset).Type Of Change
Testing Instructions
On a sample project, use this version of the SDK and try to set a value for metadata that is not null and not a string. The function will throw an error.
When trying the same experiment with an older version of the SDK, there is no compile time error but Branch SDK API calls constantly fail at run-time with a 400 "Invalid JSON" error.
cc @BranchMetrics/saas-sdk-devs for visibility.