Error handling
I've dug thru all previous issues and I can't find anything on this. I CAN'T get the damn thing to stop ending execution. I'm looking for products that don't exist (on purpose) [ to see if i need to add them]. It throws an error when looking for a sku that doesn't exist. I've tried removing the entire catch. I'd love for it just to return me the error message.. instead of stopping execution.
#0 /home/public_html/manage/lib/woocommerce-api/class-wc-api-client.php(286): WC_API_Client_HTTP_Request->dispatch() #1 /home/public_html/manage/lib/woocommerce-api/resources/abstract-wc-api-client-resource.php(122): WC_API_Client->make_api_call('GET', 'products/sku/1....', Array) #2 /home/public_html/manage/lib/woocommerce-api/resources/class-wc-api-client-resource-products.php(65): WC_API_Client_Resource->do_request() #3 /home/public_html/manage/addProducts.php(69): WC_API_Client_Resource_Products->get_by_sku(1E+28) #4 {main} thrown in /home/public_html/manage/lib/woocommerce-api/class-wc-api-client-http-request.php on line 210
I can't eval it.. that still throws end execution.
$result = eval($currentProductReviewing = $client->products->get_by_sku( 9999999999999999999999999999 ));
I guess i just need an example of how to make an error non fatal so i can do what needs done .
`catch ( WC_API_Client_Exception $e ) {
return $e->getMessage() . PHP_EOL;
return $e->getCode() . PHP_EOL;
if ( $e instanceof WC_API_Client_HTTP_Exception ) {
return ( $e->get_request() );
return ( $e->get_response() );
}
} `
still fatal
Anybody?
I would probably go with something along the lines of checking to see if your result variable is NULL or not, like this;
$sku_number = '9999999999999999999999999999';
$currentProductReviewing = $client->products->get_by_sku( $sku_number );
if (is_null($currentProductReviewing)) { echo "Need to create this product!"; } else { echo "Product already exists"; }
Or something similar, hope this helps!
having same issue, how did you manage to stop it to throw fatals?