lexik / LexikPayboxBundle

LexikPayboxBundle eases the implementation of the Paybox payment system
MIT License
40 stars 47 forks source link

Wrong error handling for CurlTransport #63

Closed lowwa132 closed 6 years ago

lowwa132 commented 8 years ago

In: https://github.com/lexik/LexikPayboxBundle/blob/master/Transport/CurlTransport.php#L63

if (!in_array($responseCode, array(0, 200, 201, 204))) {
    throw new \RuntimeException('cUrl returns some errors (cURL errno '.$curlErrorNumber.'): '.$curlErrorMessage.' (HTTP Code: '.$responseCode.')');
}

It doesn't throw an exception (even though curl_errno > 0) if you don't have a HTTP responseCode, like this one:

var_dump($response, $curlErrorNumber, $curlErrorMessage, $responseCode)

boolean false int 60 string 'SSL certificate problem: unable to get local issuer certificate' (length=63) int 0

Possible fix:

if ($curlErrorNumber > 0 || !in_array($responseCode, array(0, 200, 201, 204))) {
    throw new \RuntimeException('cUrl returns some errors (cURL errno '.$curlErrorNumber.'): '.$curlErrorMessage.' (HTTP Code: '.$responseCode.')');
}
cedric-g commented 8 years ago

Hi, indeed it's better to also check the cURL error number, I've updated the code.