-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proper check for curl error zero. (bunq/sdk_php#7) #148
Changes from 1 commit
281ab1b
325d390
d5641dd
6474a8c
b3fcc16
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,7 @@ class ApiClient | |
*/ | ||
const ERROR_ENVIRONMENT_TYPE_UNKNOWN = 'Unknown environmentType "%s"'; | ||
const ERROR_MAC_OS_CURL_VERSION = 'Your PHP seems to be linked to the MacOS provided curl binary. ' . | ||
'This is incompatible with our SDK, please reinstall by running: "brew reinstall %s --with-homebrew-curl".%s'; | ||
'This is incompatible with our SDK, please reinstall by running: "brew reinstall %s --with-homebrew-curl".%s'; | ||
|
||
/** | ||
* Public key locations. | ||
|
@@ -130,6 +130,9 @@ class ApiClient | |
*/ | ||
const COMMAND_DETERMINE_BREW_PHP_VERSION = 'brew list | egrep -e "^php[0-9]{2}$"'; | ||
|
||
const REGEX_CURL_ERROR_CODE = '/(cURL error )(?P<errorCode>\d+)/'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. constant comment |
||
const REGEX_NAMED_GOUP_ERROR_CODE = 'errorCode'; | ||
|
||
/** | ||
* @var Client | ||
*/ | ||
|
@@ -209,7 +212,7 @@ private function request( | |
$this->determineRequestOptions($body, $customHeaders) | ||
); | ||
} catch (RequestException $exception) { | ||
if ($exception->getCode() === self::ERROR_CODE_MAC_OS_CURL_BUG && $this->isMacOs()) { | ||
if ($this->isCurlErrorCodeZero($exception) && $this->isMacOs()) { | ||
die(vsprintf(self::ERROR_MAC_OS_CURL_VERSION, [$this->determineVersionPhpMacOs(), PHP_EOL])); | ||
} else { | ||
throw $exception; | ||
|
@@ -375,6 +378,21 @@ protected function determineBodyString($body): string | |
return $bodyString; | ||
} | ||
|
||
/** | ||
* @param RequestException $exception | ||
* | ||
* @return bool | ||
*/ | ||
private function isCurlErrorCodeZero(RequestException $exception): bool | ||
{ | ||
$allMatch = []; | ||
|
||
preg_match(self::REGEX_CURL_ERROR_CODE, $exception->getMessage(), $allMatch); | ||
|
||
return isset($allMatch[self::REGEX_NAMED_GOUP_ERROR_CODE]) && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a (personal preference) but I like the |
||
$allMatch[self::REGEX_NAMED_GOUP_ERROR_CODE] === self::ERROR_CODE_MAC_OS_CURL_BUG; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this not be indented, as it is a confutation of the previous line?