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

PurchasesError actual data doesn't match interface #302

Open
wsamoht opened this issue Aug 9, 2024 · 2 comments
Open

PurchasesError actual data doesn't match interface #302

wsamoht opened this issue Aug 9, 2024 · 2 comments

Comments

@wsamoht
Copy link

wsamoht commented Aug 9, 2024

Hi RevenueCat team! I thought I'd bring this up since it is still an issue in v9. I know it has been an issue since at least v7.

The actual data for PurchasesError doesn't match the interface. This is on Android at least, I don't remember on iOS 😬

There are two issues that I see. First, most of the data is wrapped in a data object. I know this has been around since v7.

Second, it says readableErrorCode is deprecated, "access readableErrorCode through userInfo.readableErrorCode". But userInfo doesn't exist in the actual data.

Actual data

image

image

The PurchaseError Interface

export interface PurchasesError {
    code: PURCHASES_ERROR_CODE;
    message: string;
    /**
     * @deprecated access readableErrorCode through userInfo.readableErrorCode
     */
    readableErrorCode: string;
    userInfo: ErrorInfo;
    underlyingErrorMessage: string;
    /**
     * @deprecated use code === Purchases.PURCHASES_ERROR_CODE.PURCHASE_CANCELLED_ERROR instead
     */
    userCancelled: boolean | null;
}

Workaround

My current workaround is a custom interface wrapping PurchaseError and a custom class.

interface PurchasesErrorWithDataInterface extends PurchasesError {
    data?: PurchasesError
}

export class PurchasesErrorWithData {
    private error: PurchasesErrorWithDataInterface

    public get code(): PURCHASES_ERROR_CODE {
        return this.error.code
    }

    public get message(): string {
        return this.error.data?.message ?? this.error.message
    }

    public get readableErrorCode(): string {
        return (
            this.error.data?.userInfo?.readableErrorCode ??
            this.error.userInfo?.readableErrorCode ??
            this.error.data?.readableErrorCode ??
            this.error.readableErrorCode
        )
    }

    public get underlyingErrorMessage(): string {
        return this.error.data?.underlyingErrorMessage ?? this.error.underlyingErrorMessage
    }

    public constructor(error: PurchasesError) {
        this.error = error
    }
}
@RCGitBot
Copy link
Collaborator

RCGitBot commented Aug 9, 2024

👀 We've just linked this issue to our internal tracker and notified the team. Thank you for reporting, we're checking this out!

@wsamoht
Copy link
Author

wsamoht commented Aug 9, 2024

iOS for a purchasePackage error looks like this:

image

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