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

Create unified error enums or types #3

Closed
vegaro opened this issue Jul 3, 2019 · 2 comments
Closed

Create unified error enums or types #3

vegaro opened this issue Jul 3, 2019 · 2 comments
Milestone

Comments

@vegaro
Copy link
Contributor

vegaro commented Jul 3, 2019

https://stackoverflow.com/questions/58410482/exposing-all-revenuecat-purchaseserrorcode-codes-in-flutter?sem=2

Expose error codes as enums or equivalent in Dart so they don't have to be hard-coded.

The proposed solution would be to add something like this

enum PurchasesErrorCode {
  UnknownError,
  PurchaseCancelledError,
  StoreProblemError,
  PurchaseNotAllowedError,
  PurchaseInvalidError,
  ProductNotAvailableForPurchaseError,
  ProductAlreadyPurchasedError,
  ReceiptAlreadyInUseError,
  InvalidReceiptError,
  MissingReceiptFileError,
  NetworkError,
  InvalidCredentialsError,
  UnexpectedBackendResponseError,
  ReceiptInUseByOtherSubscriberError,
  InvalidAppUserIdError,
  OperationAlreadyInProgressError,
  UnknownBackendError,
  InsufficientPermissionsError
}

try {
} on PlatformException catch (e) {
  PurchasesErrorCode errorCode = PurchasesErrorCode.values[int.parse(e.code)];
  switch (errorCode) {
    case PurchasesErrorCode.UnknownError:
    case PurchasesErrorCode.PurchaseCancelledError:
    case PurchasesErrorCode.StoreProblemError:
    // Add rest of cases
  }
}
@IchordeDionysos
Copy link

Would be useful!

@vegaro vegaro added this to the 3.0.0 milestone Nov 20, 2019
@vegaro vegaro modified the milestones: 3.0.0, 1.0., 1.0.0 Dec 2, 2019
@vegaro
Copy link
Contributor Author

vegaro commented Dec 2, 2019

Fixed on https://github.com/RevenueCat/purchases-flutter/releases/tag/1.0.0

You can do this now:

       try {
          PurchaserInfo purchaserInfo = await Purchases.purchasePackage(package);
        } on PlatformException catch (e) {
          var errorCode = PurchasesErrorHelper.getErrorCode(e);
          if (errorCode == PurchasesErrorCode.purchaseCancelledError) {
            print("User cancelled");
          } else if (errorCode == PurchasesErrorCode.purchaseNotAllowedError) {
            print("User not allowed to purchase");
          }
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants