WooCommerce-REST-API-Client-Library icon indicating copy to clipboard operation
WooCommerce-REST-API-Client-Library copied to clipboard

Error handling

Open bobby5892 opened this issue 9 years ago • 7 comments

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.

bobby5892 avatar Mar 08 '16 17:03 bobby5892

#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

bobby5892 avatar Mar 08 '16 17:03 bobby5892

I can't eval it.. that still throws end execution. $result = eval($currentProductReviewing = $client->products->get_by_sku( 9999999999999999999999999999 ));

bobby5892 avatar Mar 08 '16 17:03 bobby5892

I guess i just need an example of how to make an error non fatal so i can do what needs done .

bobby5892 avatar Mar 08 '16 17:03 bobby5892

`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

bobby5892 avatar Mar 08 '16 18:03 bobby5892

Anybody?

bobby5892 avatar May 07 '16 00:05 bobby5892

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!

jaythegeek avatar May 07 '16 16:05 jaythegeek

having same issue, how did you manage to stop it to throw fatals?

Max-Lumnar avatar Oct 04 '18 21:10 Max-Lumnar