diff --git a/includes/class-wc-payments-utils.php b/includes/class-wc-payments-utils.php index 43fae80e20c..1ff907ab787 100644 --- a/includes/class-wc-payments-utils.php +++ b/includes/class-wc-payments-utils.php @@ -591,16 +591,18 @@ public static function get_filtered_error_message( Exception $e ) { * @return int */ public static function get_filtered_error_status_code( Exception $e ) : int { - $status_code = 400; + $status_code = null; if ( $e instanceof API_Exception ) { - $status_code = $e->get_http_code() ?? 400; - // Sometimes hosting companies hijack this status code and return their own predefined error page. - // In this case, we want to return a 400 instead, since it will break the flow of the checkout page. - if ( 402 === $status_code ) { - $status_code = 400; - } + $status_code = $e->get_http_code(); + } + + // Sometimes hosting companies hijack the 402 status code to return their own predefined error page. + // In this case, we want to return a 400 instead, since it will break the flow of the checkout page. + if ( 402 === $status_code ) { + $status_code = 400; } - return $status_code; + + return $status_code ?? 400; } /**