api-library icon indicating copy to clipboard operation
api-library copied to clipboard

Handle better curl calls - give better error feedback

Open TiagoGouvea opened this issue 6 years ago • 1 comments

Many problems (and unnecessary issues) cames from not friendly error messages.

When AbstractAuth.php call curl on makeRequest, it don't handle many possible errors (server faults, timeouts, and things like that), that make us think that mauti api are failing.

It just say The response has unexpected status code (0) or something like that.

In my case now, I was getting that The response has unexpected status code (0) message on my prod server. Checking, I changed in prod some lines of makeRequest just for debug it:

//Make CURL request $curl = curl_init(); curl_setopt_array($curl, $options);

    $content = curl_exec($curl);
    if ($content === false) {
        var_dump(curl_error($curl));
        var_dump(curl_errno($curl));
    }

    $response = new Response($content, curl_getinfo($curl));

And then I got:

string(81) "Failed to connect to mautic.desafiodocodigo.com.br port 443: Connection timed out" 
int(7)

Checking curl errors I saw many error codes (other than 7) that could happen... but mautic api just says 'The response has unexpected status code (0)'

It's just a suggestion, to easy our life using your such amazing tool. :)


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

TiagoGouvea avatar Dec 24 '18 20:12 TiagoGouvea

Could you make a pull request please?

escopecz avatar Jan 02 '19 10:01 escopecz