Skip to content

[in_app_purchase] Standardize error handling #140225

@Reprevise

Description

@Reprevise

Use case

The in_app_purchase plugin has some some issues when it comes to error handling. Some are documentation issues, others are problems in the code.

There is no good way to catch errors universally for the completePurchase() method in InAppPurchase. On iOS, it throws a PlatformException (or a MissingPluginException since it just calls invokeMethod on a MethodChannel) and on Android it returns a Future<BillingResultWrapper> (though the return type for the platform-independent method is a Future<void>). The documentation for said method says it returns a PurchaseException, when that doesn't even exist (the closest thing I can find is a InAppPurchaseException.

With regards to the restorePurchases() method, it doesn't even document that it can throw an exception (which I think is against the Effective Dart style guide?). On Android, it can throw an InAppPurchaseException and on iOS it can throw an SKError.

Proposal

My proposal is to ensure that all methods are appropriately documented with the exceptions they can throw, namely InAppPurchaseException. I also think there is a good opportunity here to make more specific errors and have InAppPurchaseException become a sealed class instead of having to handle platform-specific error codes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listp: in_app_purchasePlugin for in-app purchasepackageflutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem team

    Type

    No type

    Projects

    Status

    Moderate, High Priority

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions