Skip to content

Commit 2761741

Browse files
authored
Add optional chaining as safety check in 'showError' (#4447)
* add optional chaining as safety check * add changelog
1 parent 4180b0b commit 2761741

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
* Update - Express Checkout: introduce new WP actions for supporting custom checkout fields for classic, shortcode-based checkout
4747
* Fix - Fix payment processing for $0 subscription with recurring coupon
4848
* Dev - Add e2e tests to cover Affirm purchase flow
49+
* Fix - Add safety check when checking error object
4950

5051
= 9.5.3 - 2025-06-23 =
5152
* Fix - Reimplement mapping of Express Checkout state values to align with WooCommerce's expected state formats

client/classic/upe/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,13 @@ jQuery( function ( $ ) {
6969
! ( errorMessage instanceof String )
7070
) {
7171
if (
72-
errorMessage.code &&
73-
getStripeServerData()[ errorMessage.code ]
72+
errorMessage?.code &&
73+
getStripeServerData()[ errorMessage?.code ]
7474
) {
75-
errorMessage = getStripeServerData()[ errorMessage.code ];
75+
errorMessage = getStripeServerData()[ errorMessage?.code ];
7676
} else {
77-
errorMessage = errorMessage.message;
77+
errorMessage =
78+
errorMessage?.message || 'An unknown error occurred.';
7879
}
7980
}
8081

client/stripe-utils/utils.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,10 +482,14 @@ export const showErrorCheckout = ( errorMessage ) => {
482482
typeof errorMessage !== 'string' &&
483483
! ( errorMessage instanceof String )
484484
) {
485-
if ( errorMessage.code && getStripeServerData()[ errorMessage.code ] ) {
486-
errorMessage = getStripeServerData()[ errorMessage.code ];
485+
if (
486+
errorMessage?.code &&
487+
getStripeServerData()[ errorMessage?.code ]
488+
) {
489+
errorMessage = getStripeServerData()[ errorMessage?.code ];
487490
} else {
488-
errorMessage = errorMessage.message;
491+
errorMessage =
492+
errorMessage?.message || 'An unknown error occurred.';
489493
}
490494
}
491495

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,5 +159,6 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
159159
* Fix - Fixes page crash when Klarna payment method is not supported in the merchant's country by returning an empty array instead of throwing an error
160160
* Fix - Fix payment processing for $0 subscription with recurring coupon
161161
* Dev - Add e2e tests to cover Affirm purchase flow
162+
* Fix - Add safety check when checking error object
162163

163164
[See changelog for full details across versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt).

0 commit comments

Comments
 (0)