Skip to content

Commit

Permalink
be more explicit on cURL errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-mukhin committed Apr 15, 2014
1 parent 82e08ac commit d7f769f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 1.2.3
- be more explicit on cURL errors

## 1.2.2
- fix sample-project composer file
- always write widget's charset
Expand Down
6 changes: 3 additions & 3 deletions src/Uploadcare/Api.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace Uploadcare;

$uploadcare_version = '1.2.2';
$uploadcare_version = '1.2.3';
define('UPLOADCARE_LIB_VERSION', sprintf('%s/%s.%s', $uploadcare_version, PHP_MAJOR_VERSION, PHP_MINOR_VERSION));

class Api
Expand Down Expand Up @@ -192,11 +192,11 @@ public function request($method, $path, $data = array(), $headers = array())
$ch_info = curl_getinfo($ch);
if ($method == 'DELETE') {
if ($ch_info['http_code'] != 302) {
throw new \Exception('Request returned unexpected http code '.$ch_info['http_code'].'. '.$data);
throw new \Exception('Request returned unexpected http code '.$ch_info['http_code'] . '. ' . curl_error($ch));
}
} else {
if (!(($ch_info['http_code'] >= 200)&&($ch_info['http_code'] < 300))) {
throw new \Exception('Request returned unexpected http code '.$ch_info['http_code'].'. '.$data);
throw new \Exception('Request returned unexpected http code '.$ch_info['http_code'] . '. ' . curl_error($ch));
}
}
curl_close($ch);
Expand Down
7 changes: 5 additions & 2 deletions src/Uploadcare/Uploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,11 @@ private function __runRequest($ch)
{
$data = curl_exec($ch);
$ch_info = curl_getinfo($ch);
if ($ch_info['http_code'] != 200) {
throw new \Exception('Request returned unexpected http code '.$ch_info['http_code'].'. '.$data);
if ($data === false) {
throw new \Exception(curl_error($ch));
}
elseif ($ch_info['http_code'] != 200) {
throw new \Exception('Unexpected HTTP status code ' . $ch_info['http_code'] . '.' . curl_error($ch));
}
curl_close($ch);
return json_decode($data);
Expand Down
1 change: 0 additions & 1 deletion tests/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,5 +377,4 @@ public function testFileConstructor()
$this->assertEquals('preview/100x100/-/effect/grayscale/', $f->default_effects);
$this->assertEquals('bill.jpg', $f->filename);
}

}

0 comments on commit d7f769f

Please sign in to comment.