Skip to content

Commit 3fe7a48

Browse files
committed
Add error handling and additional logging
1 parent 4d7e136 commit 3fe7a48

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

classes/class-wc-connect-taxjar-integration.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,7 +1444,11 @@ public function smartcalcs_cache_request( $json, $from_state ) {
14441444
$response = $response ? $response : get_transient( $cache_key );
14451445
if ( $response && 'CA' !== $from_state ) {
14461446
// If $from_state is not California, we need to check for incorrect California tax nexus.
1447-
$this->check_for_incorrect_california_tax_nexus( $response['body'], true );
1447+
try {
1448+
$this->check_for_incorrect_california_tax_nexus( $response['body'], true, $from_state );
1449+
} catch ( Exception $e ) {
1450+
$this->_log( 'Error checking for incorrect California tax nexus: ' . $e->getMessage() );
1451+
}
14481452
}
14491453
$response_code = wp_remote_retrieve_response_code( $response );
14501454
$save_error_codes = array( 404, 400 );
@@ -1458,7 +1462,11 @@ public function smartcalcs_cache_request( $json, $from_state ) {
14581462
$body = json_decode( wp_remote_retrieve_body( $response ) );
14591463
if ( 'CA' !== $from_state ) {
14601464
// If $from_state is not California, we need to check for incorrect California tax nexus.
1461-
$this->check_for_incorrect_california_tax_nexus( $body, false );
1465+
try {
1466+
$this->check_for_incorrect_california_tax_nexus( $body, false, $from_state );
1467+
} catch ( Exception $e ) {
1468+
$this->_log( 'Error checking for incorrect California tax nexus: ' . $e->getMessage() );
1469+
}
14621470
}
14631471
$is_zip_to_state_mismatch = (
14641472
isset( $body->detail )
@@ -1612,7 +1620,7 @@ public function load_taxjar_admin_new_order_assets() {
16121620
*
16131621
* @return void
16141622
*/
1615-
private function check_for_incorrect_california_tax_nexus( $response_body, $cached ): void {
1623+
private function check_for_incorrect_california_tax_nexus( $response_body, $cached, $from_state ): void {
16161624
$log_suffix = 'in TaxJar API response.';
16171625

16181626
if ( $cached ) {
@@ -1625,7 +1633,16 @@ private function check_for_incorrect_california_tax_nexus( $response_body, $cach
16251633
$has_nexus = $response_body->tax->has_nexus;
16261634

16271635
if ( 'CA' === $to_state && 'US' === $to_country && true === $has_nexus ) {
1628-
$this->_log( 'Incorrect California tax nexus detected ' . $log_suffix );
1636+
$this->_log(
1637+
sprintf(
1638+
'Incorrect California tax nexus detected %s (from_state: %s, to_state: %s, to_country: %s, has_nexus: %s).',
1639+
$log_suffix,
1640+
$from_state ?: 'unknown',
1641+
$to_state,
1642+
$to_country,
1643+
$has_nexus ? 'true' : 'false'
1644+
)
1645+
);
16291646
}
16301647
}
16311648
}

0 commit comments

Comments
 (0)