Skip to content

GigyaAuthRequest->send() doesn't have proper exception validation #117

@stratulat-vladislav

Description

@stratulat-vladislav

I have created a module which depends on gigya/drupal8 and I'm using the following API:

$responce = $helper->getGigyaApiHelper()->sendApiCall('accounts.unsubscribe', ['email' => 'zxc@zxc.zxc']);
// validate $responce and do something else

This call is throwing the following error because there's no such email registered in Gigya and prevents my code to execute "validate $responce and do something else" part:

Drupal\gigya\CmsStarterKit\GSApiException: Invalid parameter value in Drupal\gigya\CmsStarterKit\GigyaAuthRequest->send() (line 49 of /Applications/MAMP/htdocs/di-tjx-ntw-d9/web/modules/contrib/gigya-drupal/gigya/src/CmsStarterKit/GigyaAuthRequest.php).

The error is the actual error response from Gigya, but it shouldn't block me from doing something else.
I believe the code of send() method should look something like this instead:

public function send($timeout = null) {
  try {
    $res = parent::send($timeout);

    if ($res->getErrorCode() == 0)
    {
      return $res;
    }
  }
  catch (Exception $e) {
    if (!empty($res->getData())) { /* Actual error response from Gigya */
      throw new GSApiException($res->getErrorMessage(), $res->getErrorCode(), $res->getResponseText(), $res->getString("callId", "N/A"));
    } else { /* Hard-coded error in PHP SDK, or another failure */
      throw new GSException($res->getErrorMessage(), $res->getErrorCode());
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions