Skip to content

Properly Map Galaxy Errors -> PurchasesError#2927

Merged
fire-at-will merged 4 commits into
samsung-devfrom
handle-galaxy-errors
Dec 15, 2025
Merged

Properly Map Galaxy Errors -> PurchasesError#2927
fire-at-will merged 4 commits into
samsung-devfrom
handle-galaxy-errors

Conversation

@fire-at-will

Copy link
Copy Markdown
Contributor

Description

This PR extends the Error.toPurchasesError() function to properly map all error codes that are documented to us in the Samsung SDK's documentation to a PurchaseError with the most appropriate PurchaseErrorCode. This will allow us to return the most descriptive error as we can when we receive an error from the Galaxy Store.

@fire-at-will fire-at-will self-assigned this Dec 12, 2025
@fire-at-will fire-at-will requested a review from a team as a code owner December 12, 2025 19:09
@fire-at-will fire-at-will added the pr:feat A new feature label Dec 12, 2025
IAP_ERROR_CONNECT_TIMEOUT(-1011),
IAP_ERROR_NOT_EXIST_LOCAL_PRICE(-1012),
IAP_ERROR_NOT_AVAILABLE_SHOP(-1013),
IAP_ERROR_INVALID_ACCESS_TOKEN(-1015),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This isn't a typo, there is no error with the code -1014 in the docs: https://developer.samsung.com/iap/programming-guide/iap-helper-programming.html#ErrorVo-and-Response-code

-> PurchasesErrorCode.StoreProblemError
GalaxyErrorCode.IAP_ERROR_NOT_AVAILABLE_SHOP -> PurchasesErrorCode.PurchaseNotAllowedError
GalaxyErrorCode.IAP_ERROR_INVALID_ACCESS_TOKEN -> PurchasesErrorCode.InvalidCredentialsError
GalaxyErrorCode.IAP_ERROR_NONE -> return null // This means that the ErrorVo isn't an error

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It didn't feel right to return a PurchasesError with an unknown code or something like that here, since this galaxy error code explicitly means that an error didn't occur.

This code really shouldn't be executed, since most calling code will be checking our ErrorVo.isError() function, but I still added this here to exercise defensive programming.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmm I guess the main problem is that this makes the return nullable, which we need to handle everywhere... Maybe it's worth returning the unknown message here but just log something before that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it definitely muddies up the call sites. Updated to return an UnknownError in 132448c 👍

@tonidero tonidero left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks great! 🙌

GalaxyErrorCode.IAP_ERROR_INVALID_ACCESS_TOKEN to PurchasesErrorCode.InvalidCredentialsError,
)

expectedMappings.forEach { (galaxyCode, purchasesErrorCode) ->

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Instead of iterating over the hardcoding mappings here, should we iterate over all values of the GalaxyErrorcode enum, so we make sure we catch all of them? Then, we can convert expectedMappings to a map, for easier access to the expected PurchasesErrorCode.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I love that idea! That'll make sure that we remember to add future mappings to this test :)

Made the change in 09c48d5

-> PurchasesErrorCode.StoreProblemError
GalaxyErrorCode.IAP_ERROR_NOT_AVAILABLE_SHOP -> PurchasesErrorCode.PurchaseNotAllowedError
GalaxyErrorCode.IAP_ERROR_INVALID_ACCESS_TOKEN -> PurchasesErrorCode.InvalidCredentialsError
GalaxyErrorCode.IAP_ERROR_NONE -> return null // This means that the ErrorVo isn't an error

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmm I guess the main problem is that this makes the return nullable, which we need to handle everywhere... Maybe it's worth returning the unknown message here but just log something before that?

@fire-at-will fire-at-will merged commit 6c3ed30 into samsung-dev Dec 15, 2025
0 of 2 checks passed
@fire-at-will fire-at-will deleted the handle-galaxy-errors branch December 15, 2025 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr:feat A new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants