Skip to content

Commit

Permalink
Fixes #118 - partial reverts PR #67 - handling legacy webdriver 4xx r…
Browse files Browse the repository at this point in the history
…esponses
  • Loading branch information
robocoder committed Aug 9, 2022
1 parent 1650c80 commit 99957bf
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions lib/WebDriver/AbstractWebDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,17 @@ protected function curl($requestMethod, $command, $parameters = null, $extraOpti
);
}

// According to https://w3c.github.io/webdriver/webdriver-spec.html all 4xx responses are to be considered
// an error and return plaintext, while 5xx responses are json encoded
if ($httpCode >= 400 && $httpCode <= 499) {
throw WebDriverException::factory(
WebDriverException::CURL_EXEC,
'Webdriver http error: ' . $httpCode . ', payload :' . substr($rawResult, 0, 1000)
);
}

$result = json_decode($rawResult, true);

if (! empty($rawResult) && $result === null && json_last_error() != JSON_ERROR_NONE) {
// Legacy webdriver 4xx responses are to be considered // an error and return plaintext
if ($httpCode >= 400 && $httpCode <= 499) {
throw WebDriverException::factory(
WebDriverException::CURL_EXEC,
'Webdriver http error: ' . $httpCode . ', payload :' . substr($rawResult, 0, 1000)
);
}

throw WebDriverException::factory(
WebDriverException::CURL_EXEC,
'Payload received from webdriver is not valid json: ' . substr($rawResult, 0, 1000)
Expand Down

0 comments on commit 99957bf

Please sign in to comment.