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
Improve error control #403
Comments
Right now we have $curl = new Curl();
$curl->get($url, $data);
if ($curl->error) {
// Handle error.
} else {
// Handle response.
} What would you like to be able to do? |
Hi, $curl = new Curl();
try {
$curl->get($url, $data);
}
catch (CurlException $e) {
MyErrorLogger::log($e->getMessage())
} It means that the logic to read the error message should be inside the |
Try/Catch For:
|
Try/Catch Against:
|
A backwards-compatible version could look like this: $curl = new Curl();
$curl->get($url, $data);
try {
$curl->catch();
} catch (CurlException $e) {
// Handle error.
MyErrorLogger::log($e->getMessage())
} |
This would be really useful if there was an optional shorthand like the existing $curl = new Curl();
$curl->fragile();
$curl->get("http://never-resolve"); // throws immediately and tells what happened I think this is a highly reusable scenario, because when debugging we rarely care to handle CURL errors, just need to know what error happened. |
One solution would be to implement something like $curl = new Curl();
$curl->raiseErrors();
try {
$curl->get($url, $data);
} catch (CurlException $e) {
// Handle error.
} However, exceptions wouldn't ever be raised if $curl = new Curl();
try {
$curl->get($url, $data);
} catch (CurlException $e) {
// Exception never raised because $curl->raiseErrors() wasn't called.
} |
I am missing a better error control on Curl class. May be, having the posibility to decorate the class with some methods to control errors and throw the needed exceptions. That would not change the class behaviour and would add a good feature.
Do you think it could be interesting for the project?
The text was updated successfully, but these errors were encountered: