Re: [w3c/payment-request] Improved error codes (Issue #1040)

Hi @dtjones404, the error handling code would be similar to the following. Is that something that you would consider safe to add to your code-base even today, given that it's hidden behind feature detection?

```js
const paymentRequest = new PaymentRequest(
        supportedMethods, paymentDetails, {enableOperationErrorCode: true});
// ...
#handlePaymentError(
    error,
  ) {
    if (!PaymentRequest. isErrorCodeSupported || !PaymentRequest.isErrorCodeSupported("OperationError")) {
      // Check error message.
      if (
        [
          "Request cancelled", // used by Chrome <= 76, Opera 63
          "User closed the Payment Request UI.", // Chrome 77+, Edge 79+, Opera 64+
        ].includes(
          error.message,
        )
      ) {
        this.paymentFlowOptions.onCancel?.();
      } else {
        this.paymentFlowOptions.onError?.(error);
      }
    } else {
        // Check error code.
        if (error.name === "OperationError") {
          this.paymentFlowOptions.onError?.(error);
        } else {
          this.paymentFlowOptions.onCancel?.();
        }
    }
  }

```

-- 
Reply to this email directly or view it on GitHub:
https://github.com/w3c/payment-request/issues/1040#issuecomment-2528171605
You are receiving this because you are subscribed to this thread.

Message ID: <w3c/payment-request/issues/1040/2528171605@github.com>

Received on Monday, 9 December 2024 14:46:49 UTC