zoho / zohocrm-php-sdk-6.0

Apache License 2.0
1 stars 2 forks source link

Status code 0 on search records #13

Closed rosskevin closed 2 months ago

rosskevin commented 2 months ago

We are receiving numerous unknown responses from the SDK. It is totally unknown, sometimes it works, sometimes it doesn't. I tried logging the response object, but it is simply empty:

[12-Sep-2024 18:02:16 UTC] [FindOne] !!!!!!!!Unknown error
[12-Sep-2024 18:02:16 UTC] [FindOne] com\zoho\crm\api\util\APIResponse Object
(
    [headers:com\zoho\crm\api\util\APIResponse:private] => Array
        (
        )

    [statusCode:com\zoho\crm\api\util\APIResponse:private] => 0
    [object:com\zoho\crm\api\util\APIResponse:private] => 
    [isExpected:com\zoho\crm\api\util\APIResponse:private] => 
)

[12-Sep-2024 18:02:16 UTC] PHP Fatal error:  Uncaught Exception: Unknown response type.  Status: 0

The code running this:

  public function run(string $module, $criteria): Record|null
  {
    $recordOperations = new RecordOperations($module);
    $paramInstance = new ParameterMap();
    $paramInstance->add(SearchRecordsParam::criteria(), $criteria);
    $headerInstance = new HeaderMap();
    $response = $recordOperations->searchRecords($paramInstance, $headerInstance);
    $status = intval($response->getStatusCode());
    if ($status == 204) {
      // no content
      return null;
    } else if ($response->isExpected()) {
      $responseHandler = $response->getObject();
      if ($responseHandler instanceof ResponseWrapper) {
        $responseWrapper = $responseHandler;
        $records = $responseWrapper->getData();
        if ($records != null) {

          if (count($records) > 1) {
            throw new \Exception($module . " findOne returned more than one record for criteria: " . $criteria);
          }

          return $records[0];
        }
      } else if ($responseHandler instanceof APIException) {
        Exceptions::throwAPIException($this->log, $responseHandler);
      }
    } else {
      $this->log->error("!!!!!!!!Unknown error");
      $this->log->error($response);
      throw new \Exception("Unknown response type.  Status: " . $response->getStatusCode());
    }

    return null;
  }

These are the sdk logs for that call:

  2024-09-12 18:02:44 com\zoho\api\logger\SDKLogger INFO Initialization successful  in Environment : https://www.zohoapis.com.
2024-09-12 18:02:44 com\zoho\api\logger\SDKLogger INFO GET - URL = https://www.zohoapis.com/crm/v6/Distributors/search?criteria=%28RPC_Code%3Aequals%3ASC-ML-META%29 , headers = {"Authorization":" ## can't disclose ## ","X-ZOHO-SDK":"Linux\/5.4.0-1132-gcp\/php-6.0\/8.3.10:4.0.0"} , PARAMS = {"criteria":"(RPC_Code:equals:SC-ML)"}.
2024-09-12 18:02:46 com\zoho\api\logger\SDKLogger SEVERE Error response :Operation timed out after 2000 milliseconds with 0 bytes received

Why am I receiving timeouts when attempting to search and get a single record by custom field code? Why isn't this an http status 408?

rosskevin commented 2 months ago

I'll note that the custom field is unique, but was not set as such. I have now added that and hope that it makes responses more timely.

I do think the lack of proper status 408 yielded from SDK in a timeout situation is a bug and should be addressed.

raja-7453 commented 2 months ago

Hi @rosskevin Thanks for informing! Please forward the issue details and SDK configuration samples to support@zohocrm.com and we'll take things forward.

rosskevin commented 2 months ago

@raja-7453 no thank you. Last time I did that, it was front line support sending me to basic articles. This is an SDK bug, and it should be dealt with directly in the project that houses the code, or a developer support issue tracker.

I shouldn't have to spend that much time contributing information to help solve a common code problem.

raja-7453 commented 1 month ago

Since this is because of the configured timeout, it has been handled considering it as an SDK-exception instead of a response from the API (which is the one that could return the status code).

So, from this 6.0.0 version, it will be thrown as Error response : Operation timed out after 2000 milliseconds with 0 bytes received if timeout occurs.