Improve webhook deletion error output

This commit is contained in:
Alex P 2023-03-09 10:46:25 +02:00
parent c77f20d2f9
commit 3d3fe37185
No known key found for this signature in database
GPG key ID: 54487A734A204D71

View file

@ -175,12 +175,12 @@ class WebhookEndpoint {
* *
* @param Webhook $hook The webhook to delete. * @param Webhook $hook The webhook to delete.
* *
* @return bool
* @throws RuntimeException If the request fails. * @throws RuntimeException If the request fails.
* @throws PayPalApiException If the request fails.
*/ */
public function delete( Webhook $hook ): bool { public function delete( Webhook $hook ): void {
if ( ! $hook->id() ) { if ( ! $hook->id() ) {
return false; return;
} }
$bearer = $this->bearer->bearer(); $bearer = $this->bearer->bearer();
@ -198,7 +198,18 @@ class WebhookEndpoint {
__( 'Not able to delete the webhook.', 'woocommerce-paypal-payments' ) __( 'Not able to delete the webhook.', 'woocommerce-paypal-payments' )
); );
} }
return wp_remote_retrieve_response_code( $response ) === 204;
$status_code = (int) wp_remote_retrieve_response_code( $response );
if ( 204 !== $status_code ) {
$json = null;
if ( is_array( $response ) ) {
$json = json_decode( $response['body'] );
}
throw new PayPalApiException(
$json,
$status_code
);
}
} }
/** /**