Skip to content

Commit da1c62b

Browse files
Daniel Rey LopezDanReyLop
authored andcommitted
Fix crash when there's an error requesting taxes from the WCS proxy.
1 parent 7dbaa22 commit da1c62b

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,15 @@ public function _log( $message ) {
181181
$this->logger->log( $formatted_message, 'WCS Tax' );
182182
}
183183

184+
/**
185+
* @param $message
186+
*/
187+
public function _error( $message ) {
188+
$formatted_message = is_scalar( $message ) ? $message : json_encode( $message );
189+
190+
$this->logger->error( $formatted_message, 'WCS Tax' );
191+
}
192+
184193
/**
185194
* Wrapper to avoid calling calculate_totals() for admin carts.
186195
*
@@ -685,11 +694,11 @@ public function smartcalcs_request( $json ) {
685694
) );
686695

687696
if ( is_wp_error( $response ) ) {
688-
return new WP_Error( 'request', __( 'There was an error retrieving the tax rates. Please check your server configuration.' ) );
697+
$this->_error( 'Error retrieving the tax rates. Received (' . $response->get_error_code() . '): ' . $response->get_error_message() );
689698
} elseif ( 200 == $response['response']['code'] ) {
690699
return $response;
691700
} else {
692-
$this->_log( 'Received (' . $response['response']['code'] . '): ' . $response['body'] );
701+
$this->_error( 'Error retrieving the tax rates. Received (' . $response['response']['code'] . '): ' . $response['body'] );
693702
}
694703
}
695704

@@ -847,4 +856,4 @@ public function backup_existing_tax_rates() {
847856
$wpdb->query( 'TRUNCATE ' . $wpdb->prefix . 'woocommerce_tax_rates' );
848857
$wpdb->query( 'TRUNCATE ' . $wpdb->prefix . 'woocommerce_tax_rate_locations' );
849858
}
850-
}
859+
}

0 commit comments

Comments
 (0)