Skip to content

Commit

Permalink
exception on fail create
Browse files Browse the repository at this point in the history
  • Loading branch information
mipxtx committed Jul 10, 2018
1 parent 4d436ce commit 82ef869
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions lib/RedmineApi/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,13 @@ public function log($str) {
if (php_sapi_name() != "cli") {
//echo "<pre>";
}
echo(
strlen($str) > $this->debugStringLength

$str = strlen($str) > $this->debugStringLength
? (mb_strcut($str, 0, $this->debugStringLength) . "...")
: $str
);
echo "\n";
: $str;
error_log($str);
echo($str . "\n");

if (php_sapi_name() != "cli") {
//echo "</pre>";
}
Expand All @@ -88,10 +89,17 @@ public function prepareCurl($method, $requestUrl, array $data = []) {
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, $this->timeout * 1000000);
$this->log("connecting to $requestUrl");

$msg = $method . " " . $requestUrl;

if ($data) {
$msg .= "\n" . $data;
}

$this->log('send: ' . $msg);

if ($method != 'GET') {
$data = json_encode($data);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$this->log($data);
}

if ($method == 'POST') {
Expand All @@ -111,7 +119,7 @@ public function prepareCurl($method, $requestUrl, array $data = []) {
CURLOPT_HTTPHEADER,
[
'Content-Type: application/json',
'X-Redmine-API-Key: ' . $this->key
'X-Redmine-API-Key: ' . $this->key,
]
);

Expand All @@ -122,11 +130,11 @@ public function getResponse($ch) {
$body = curl_exec($ch);
curl_close($ch);

$this->log($body);

$this->log('resp: ' . $body);
$result = json_decode($body, 1);

if (isset($result['error'])) {
throw new Exception($result['error']);
throw new \RuntimeException($result['error']);
}

return $result;
Expand Down

0 comments on commit 82ef869

Please sign in to comment.