You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In case a cURL requests failed, \Web::instance()->request($url, $options) returns a string representation of the error in the returned Array.
This makes it hard to handle different error types. I suggest adding a newerrorCode to the returned Array.
Suggestion:
Add new errorCode to returned Array. Example shows a request that timedOut :
[
'body' => '',
'headers' => [],
'engine' => 'cURL',
'cached' => false,
'error' => 'Connection timed out after 16 milliseconds',
'errorCode' => 28 // <== new entry
]
ob_start();
curl_exec($curl);
if($errCode = curl_errno($curl)){ // e.g. 28 - Must be done before curl_close(), returns 0||null if no error found$errMessage = curl_strerror($errCode ); // e.g. "Timeout was reached"$err = curl_error($curl) // e.g. "Connection timed out after 16 milliseconds"
}
curl_close($curl);
$body=ob_get_clean();
... and add $errCode (maybe $errMessage as well) to the response Array.
As you can see, the Strings are slightly different.
Test:
Either set $options['timeout'] = 1 as config option for a valid request and hope for a timeout, or add this to the _curl($url,$options) method and set the timeout to e.g. 10ms:
[
'body' => '',
'headers' => [],
'engine' => 'cURL',
'cached' => false,
'error' => 'Connection timed out after 16 milliseconds',
'errors' => {[ //new name to keep backward compatible.
[
'message' =>'Connection timed out after 16 milliseconds',
'code' => 28
], //array in case there are more then one error
]}
]
Return an array with errors (and errorCode) can also work. But I´m not sure if request can fail with multiple errors.
We should also think about _stream() and _socket() return Array. All 3 methods return the same result Array.
Anyway it would useful to have the code and work with them like:
$response = \Web::instance()->request($url, $options);
switch($response['errorCode']){
caseCURLE_URL_MALFORMAT:
$f3->error(500, 'WTF!');
break;
caseCURLE_OPERATION_TIMEOUTED:
// no error here, maybe try to resend same request again up to 3 times...break;
}
Issue:
In case a cURL requests failed,
\Web::instance()->request($url, $options)
returns a string representation of the error in the returned Array.This makes it hard to handle different error types. I suggest adding a new
errorCode
to the returned Array.Suggestion:
Add new
errorCode
to returned Array. Example shows a request that timedOut :Implementation (suggestion):
Replace this code https://github.com/bcosca/fatfree/blob/master/lib/web.php#L303
... with something like this:
... and add
$errCode
(maybe$errMessage
as well) to the response Array.As you can see, the Strings are slightly different.
Test:
Either set
$options['timeout'] = 1
as config option for a valid request and hope for a timeout,or add this to the
_curl($url,$options)
method and set the timeout to e.g. 10ms:The text was updated successfully, but these errors were encountered: