Skip to content

Commit 5be1aff

Browse files
author
Helperhaps
committed
Merge branch 'dev'
2 parents 7a66f4a + a536778 commit 5be1aff

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
namespace JPush\Exceptions;
3+
4+
class ServiceNotAvaliable extends JPushException {
5+
6+
private $code;
7+
private $headers;
8+
9+
function __construct($response){
10+
$this->http_code = $response['http_code'];
11+
$this->headers = $response['headers'];
12+
$this->message = $response['body'];
13+
}
14+
15+
function __toString() {
16+
return "\n" . __CLASS__ . " -- [{$this->code}]: {$this->message} \n";
17+
}
18+
19+
public function getHttpCode() {
20+
return $this->http_code;
21+
}
22+
public function getHeaders() {
23+
return $this->headers;
24+
}
25+
}

src/JPush/Http.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,13 @@ private static function sendRequest($client, $url, $method, $body=null, $times=1
116116
}
117117

118118
public static function processResp($response) {
119-
if($response['http_code'] === 200) {
119+
$data = json_decode($response['body'], true);
120+
121+
if (is_null($data)) {
122+
throw new ServiceNotAvaliable($response);
123+
} elseif ($response['http_code'] === 200) {
120124
$result = array();
121-
$data = json_decode($response['body'], true);
122-
if (!is_null($data)) {
123-
$result['body'] = $data;
124-
}
125+
$result['body'] = $data;
125126
$result['http_code'] = $response['http_code'];
126127
$result['headers'] = $response['headers'];
127128
return $result;

src/JPush/version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?php
22
namespace JPush;
33

4-
const VERSION = '3.5.11';
4+
const VERSION = '3.5.12';

0 commit comments

Comments
 (0)