55use Redmine \Exception ;
66use Redmine \Exception \InvalidParameterException ;
77use Redmine \Exception \SerializerException ;
8+ use Redmine \Exception \UnexpectedResponseException ;
89
910/**
1011 * @see http://www.redmine.org/projects/redmine/wiki/Rest_News
@@ -24,7 +25,7 @@ class News extends AbstractApi
2425 * @param array $params optional parameters to be passed to the api (offset, limit, ...)
2526 *
2627 * @throws InvalidParameterException if $projectIdentifier is not of type int or string
27- * @throws SerializerException if response body could not be converted into array
28+ * @throws UnexpectedResponseException if response body could not be converted into array
2829 *
2930 * @return array list of news found
3031 */
@@ -37,7 +38,11 @@ final public function listByProject($projectIdentifier, array $params = []): arr
3738 ));
3839 }
3940
40- $ this ->news = $ this ->retrieveData ('/projects/ ' .strval ($ projectIdentifier ).'/news.json ' , $ params );
41+ try {
42+ $ this ->news = $ this ->retrieveData ('/projects/ ' .strval ($ projectIdentifier ).'/news.json ' , $ params );
43+ } catch (SerializerException $ th ) {
44+ throw new UnexpectedResponseException ('The Redmine server responded with an unexpected body. ' , $ th ->getCode (), $ th );
45+ }
4146
4247 return $ this ->news ;
4348 }
@@ -49,13 +54,17 @@ final public function listByProject($projectIdentifier, array $params = []): arr
4954 *
5055 * @param array $params optional parameters to be passed to the api (offset, limit, ...)
5156 *
52- * @throws SerializerException if response body could not be converted into array
57+ * @throws UnexpectedResponseException if response body could not be converted into array
5358 *
5459 * @return array list of news found
5560 */
5661 final public function list (array $ params = []): array
5762 {
58- $ this ->news = $ this ->retrieveData ('/news.json ' , $ params );
63+ try {
64+ $ this ->news = $ this ->retrieveData ('/news.json ' , $ params );
65+ } catch (SerializerException $ th ) {
66+ throw new UnexpectedResponseException ('The Redmine server responded with an unexpected body. ' , $ th ->getCode (), $ th );
67+ }
5968
6069 return $ this ->news ;
6170 }
@@ -87,6 +96,10 @@ public function all($project = null, array $params = [])
8796 return false ;
8897 }
8998
99+ if ($ e instanceof UnexpectedResponseException && $ e ->getPrevious () !== null ) {
100+ $ e = $ e ->getPrevious ();
101+ }
102+
90103 return $ e ->getMessage ();
91104 }
92105 }
0 commit comments