Skip to content

Commit 13ca3d1

Browse files
authored
Improve error messages (#4863)
* Update error messages to distinguish between request and responses * Add changelog entry * Update tests
1 parent ba5f205 commit 13ca3d1

File tree

4 files changed

+6
-4
lines changed

4 files changed

+6
-4
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Dev - Removes all references to the UPE-enabled feature flag
55
* Dev - Removes deprecated promotional banners (related to legacy checkout)
66
* Fix - Error when using Puerto Rico addresses with express checkouts
7+
* Tweak - Improve error messages when Stripe API requests fail to better distinguish between request and retrieval errors
78

89
= 10.2.0 - 2025-12-08 =
910
* Dev - Refactor display logic for payment method issue pills

includes/class-wc-stripe-api.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ public static function request( $request, $api = 'charges', $method = 'POST', $w
266266
];
267267
self::log_error_response( $response, $api, $method, $error_data );
268268

269-
throw new WC_Stripe_Exception( print_r( $response, true ), __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) );
269+
throw new WC_Stripe_Exception( print_r( $response, true ), __( 'There was a problem sending a request to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) );
270270
}
271271

272272
$response_body = json_decode( $response['body'] );
@@ -374,7 +374,7 @@ public static function retrieve( $api ) {
374374
];
375375
self::log_error_response( $response, $api, 'GET', $error_data );
376376

377-
return new WP_Error( 'stripe_error', __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) );
377+
return new WP_Error( 'stripe_error', __( 'There was a problem retrieving data from the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) );
378378
}
379379

380380
$response_body = json_decode( $response['body'] );

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,5 +143,6 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
143143
* Fix - Error when using Puerto Rico addresses with express checkouts
144144
* Dev - Removes all references to the UPE-enabled feature flag
145145
* Dev - Removes deprecated promotional banners (related to legacy checkout)
146+
* Tweak - Improve error messages when Stripe API requests fail to better distinguish between request and retrieval errors
146147

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

tests/phpunit/WC_Stripe_API_Test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,11 +291,11 @@ public function test_log_error_response( $response, string $api, string $method,
291291
if ( 'GET' === $method ) {
292292
$this->assertInstanceof( \WP_Error::class, $result );
293293
$this->assertEquals( 'stripe_error', $result->get_error_code() );
294-
$this->assertEquals( __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ), $result->get_error_message() );
294+
$this->assertEquals( __( 'There was a problem retrieving data from the Stripe API endpoint.', 'woocommerce-gateway-stripe' ), $result->get_error_message() );
295295
} else {
296296
$this->assertInstanceof( \WC_Stripe_Exception::class, $caught_exception );
297297
$this->assertEquals( print_r( $response, true ), $caught_exception->getMessage() );
298-
$this->assertEquals( __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ), $caught_exception->getLocalizedMessage() );
298+
$this->assertEquals( __( 'There was a problem sending a request to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ), $caught_exception->getLocalizedMessage() );
299299
}
300300
}
301301

0 commit comments

Comments
 (0)