Closed phoglenix closed 3 years ago
s/throwing errors/rejecting promises/ SGTM.
Is there currently any case where we reject the promise to getDigitalGoodsService
?
Yep, I meant rejecting promises by throwing errors (seems to be the standard way).
No, currently we never reject the promise to getDigitalGoodsService
. Just return null if there are any issues.
Should we do both? For example, if the context does not support digital goods API, return null. If the context supports digital goods, but not with this payment method, then return NotSupportedError.
I would rather that we limit the number of things that clients have to check.
There are three levels of "unsupported" here:
Case 1 can only be handled by the non-existence of the getDigitalGoodsService
method. You're proposing that Case 2 returns null
and Case 3 rejects with NotSupportedError
? Then developers need to have 3 separate checks (an existence check on getDigitalGoodsService
, a try-catch around the call, and a null
check on its result). I don't think it's really worth distinguishing Cases 2 and 3 (in fact I'm not really sure what the difference is). If we do want to distinguish them, we should reject with different errors so that if the developer doesn't care, they can just catch all exceptions.
I agree with mgiuca@. I think if the DG API is supported (ie. window.getDigitalGoodsService is defined) then it's more helpful to reject calls with a specific error than returning null to represent one of the failure cases.
This is fixed by v2.0 changes (https://github.com/WICG/digital-goods/pull/34)
I am stuck at this, getDigitalGoodsService
const PAYMENT_METHOD = "https://play.google.com/billing service = await window.getDigitalGoodsService(PAYMENT_METHOD);
shows Promise error "DOMException: unsupported context" , what could be possible reason ? the function getDigitalGoodsService is defined and testing in a TWA from Playstore.
@MrVibe did you manage to solve it? I have the same issue. I think it's probably related to a PWA installed via Browser instead of via Play Store. So this is what the "unsupported context" would mean in this case.
This would let the API return more informative error messages to the developer, which could optionally be handled programmatically e.g. if a payment method is unavailable, try another, but if we're not in a supported context, stop trying. It would also avoid spamming the JS console if errors were caught and handled (compared with the current way of exposing errors, which is to output to the JS console directly).