Skip to content

Commit

Permalink
Backport fixes from master branch
Browse files Browse the repository at this point in the history
  • Loading branch information
robocoder committed Mar 30, 2022
1 parent 6bc1f44 commit 608e8b2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
18 changes: 8 additions & 10 deletions lib/WebDriver/AbstractWebDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,12 @@ protected function curl($requestMethod, $command, $parameters = null, $extraOpti
}

$value = (is_array($result) && array_key_exists('value', $result)) ? $result['value'] : null;
$message = (is_array($value) && array_key_exists('message', $value)) ? $value['message'] : null;
$message = (is_array($result) && array_key_exists('message', $result))
? $result['message']
: ((is_array($value) && array_key_exists('message', $value)) ? $value['message'] : null);
$error = (is_array($result) && array_key_exists('error', $result))
? $result['error']
: ((is_array($value) && array_key_exists('error', $value)) ? $value['error'] : null);

// if not success, throw exception
if (isset($result['status']) && (int) $result['status'] !== 0) {
Expand All @@ -167,16 +172,9 @@ protected function curl($requestMethod, $command, $parameters = null, $extraOpti
);
}

if (isset($value['error'])) {
if (isset($error)) {
throw WebDriverException::factory(
$value['error'],
$message
);
}

if (isset($value['ready']) && $value['ready'] !== true) {
throw WebDriverException::factory(
WebDriverException::CURL_EXEC,
$error,
$message
);
}
Expand Down
13 changes: 7 additions & 6 deletions lib/WebDriver/Service/CurlService.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

namespace WebDriver\Service;

use WebDriver\Exception as WebDriverException;
use WebDriver\Exception\CurlExec as CurlExecException;

/**
* WebDriver\Service\CurlService class
Expand Down Expand Up @@ -110,19 +110,20 @@ public function execute($requestMethod, $url, $parameters = null, $extraOptions
) {
curl_close($curl);

throw WebDriverException::factory(
WebDriverException::CURL_EXEC,
$e = new CurlExecException(
sprintf(
"Curl error thrown for http %s to %s%s\n\n%s",
$requestMethod,
$url,
$parameters && is_array($parameters) ? ' with params: ' . json_encode($parameters) : '',
$error
),
$errno,
null,
$info
$errno
);

$e->setCurlInfo($info);

throw $e;
}

curl_close($curl);
Expand Down

0 comments on commit 608e8b2

Please sign in to comment.