codeswholesale / codeswholesale-sdk-php

A PHP wrapper for CodesWholesale's API
Apache License 2.0
36 stars 21 forks source link

Product Description queries not working with sample too #39

Closed officialmmt closed 3 years ago

officialmmt commented 3 years ago

I trying to print product descriptions but challanging many errors Fatal error: Uncaught InvalidArgumentException: No link in resource description in C:\laragon\www\example\vendor\codeswholesale\sdk\src\CodesWholesale\Resource\Resource.php:38 Stack trace: #0 C:\laragon\www\example\vendor\codeswholesale\sdk\src\CodesWholesale\Resource\Product.php(188): CodesWholesale\Resource\Resource->getHrefRel('description') #1 C:\laragon\www\example\single-product-with-description.php(64): CodesWholesale\Resource\Product->getDescriptionHref() #2 {main} thrown in C:\laragon\www\example\vendor\codeswholesale\sdk\src\CodesWholesale\Resource\Resource.php on line 38

EagleSH commented 3 years ago

yes, i have confirm this too.

fefrik commented 3 years ago

You can catch it:

try { 
    $productDescription = \CodesWholesale\Resource\ProductDescription::get($product->getDescriptionHref());
} catch (InvalidArgumentException $e) {
   LogService::toFile("DescriptionHref is not found");
}
officialmmt commented 3 years ago

@fefrik I am testing https://github.com/codeswholesale/codeswholesale-sdk-php/blob/master/examples/single-product-with-description.php this is the same as your answer.

officialmmt commented 3 years ago

@fefrik I tried live version and real client rather than sandbox credential. And it is work but only with URL. $product = \CodesWholesale\Resource\ProductDescription::get("https://api.codeswholesale.com/v2/products/cfd6a94d-d497-4251-974d-9b1f2ca640a2/description"); $product->getDescriptionHref() giving no link error like below. $product = \CodesWholesale\Resource\ProductDescription::get($product->getDescriptionHref()); So how do you handle it?

fefrik commented 3 years ago

I'm catching InvalidArgumentException, therefore if there is something wrong with argument, I don't care about description at all and jump over it.

Actually, I am using tripple catch:

try {
     $description = $product->getDescriptionHref();
     $productDescription = \CodesWholesale\Resource\ProductDescription::get($description);
     ....
} catch (InvalidArgumentException $e) {
                LogService::toFile("DescriptionHref is not found"); 
} catch (\CodesWholesale\Resource\ResourceError $e) {
                if ($e->isInvalidToken()) {
                    LogService::toFile("ProductDescription Error - Invalid Token. " . $e->getTraceAsString());
                    // try it once again... 
                }
} catch (Exception $error) {
                    LogService::toCatalogFile("ProductDescription Error: " . $error->getMessage());
}
officialmmt commented 3 years ago

So we getting this error because of we using windows 10 php

EagleSH commented 3 years ago

no no, this error on linux also (tried on different systems and even macos)

officialmmt commented 3 years ago

Docker containers have it too.