Skip to content

Commit c132efc

Browse files
authored
Merge pull request #340 from Art4/339-add-new-exception-on-unexpected-response
Add new UnexpectedResponseException
2 parents cd10480 + ec0296e commit c132efc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+756
-40
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3030
- New method `Redmine\Api\User::list()` to list users.
3131
- New method `Redmine\Api\Version::listByProject()` to list versions from a project.
3232
- New method `Redmine\Api\Wiki::listByProject()` to list wiki pages from a project.
33+
- New exception `Redmine\Exception\UnexpectedResponseException` if the Redmine server responded with an unexpected body.
3334

3435
### Deprecated
3536

src/Redmine/Api/CustomField.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Redmine\Exception;
66
use Redmine\Exception\SerializerException;
7+
use Redmine\Exception\UnexpectedResponseException;
78

89
/**
910
* Listing custom fields.
@@ -23,13 +24,17 @@ class CustomField extends AbstractApi
2324
*
2425
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
2526
*
26-
* @throws SerializerException if response body could not be converted into array
27+
* @throws UnexpectedResponseException if response body could not be converted into array
2728
*
2829
* @return array list of custom fields found
2930
*/
3031
final public function list(array $params = []): array
3132
{
32-
$this->customFields = $this->retrieveData('/custom_fields.json', $params);
33+
try {
34+
$this->customFields = $this->retrieveData('/custom_fields.json', $params);
35+
} catch (SerializerException $th) {
36+
throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th);
37+
}
3338

3439
return $this->customFields;
3540
}
@@ -56,6 +61,10 @@ public function all(array $params = [])
5661
return false;
5762
}
5863

64+
if ($e instanceof UnexpectedResponseException && $e->getPrevious() !== null) {
65+
$e = $e->getPrevious();
66+
}
67+
5968
return $e->getMessage();
6069
}
6170
}

src/Redmine/Api/Group.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Redmine\Exception;
66
use Redmine\Exception\MissingParameterException;
77
use Redmine\Exception\SerializerException;
8+
use Redmine\Exception\UnexpectedResponseException;
89
use Redmine\Serializer\PathSerializer;
910
use Redmine\Serializer\XmlSerializer;
1011

@@ -26,13 +27,17 @@ class Group extends AbstractApi
2627
*
2728
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
2829
*
29-
* @throws SerializerException if response body could not be converted into array
30+
* @throws UnexpectedResponseException if response body could not be converted into array
3031
*
3132
* @return array list of groups found
3233
*/
3334
final public function list(array $params = []): array
3435
{
35-
$this->groups = $this->retrieveData('/groups.json', $params);
36+
try {
37+
$this->groups = $this->retrieveData('/groups.json', $params);
38+
} catch (SerializerException $th) {
39+
throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th);
40+
}
3641

3742
return $this->groups;
3843
}
@@ -59,6 +64,10 @@ public function all(array $params = [])
5964
return false;
6065
}
6166

67+
if ($e instanceof UnexpectedResponseException && $e->getPrevious() !== null) {
68+
$e = $e->getPrevious();
69+
}
70+
6271
return $e->getMessage();
6372
}
6473
}

src/Redmine/Api/Issue.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Redmine\Exception;
66
use Redmine\Exception\SerializerException;
7+
use Redmine\Exception\UnexpectedResponseException;
78
use Redmine\Serializer\JsonSerializer;
89
use Redmine\Serializer\PathSerializer;
910
use Redmine\Serializer\XmlSerializer;
@@ -40,13 +41,17 @@ class Issue extends AbstractApi
4041
*
4142
* @param array $params the additional parameters (cf available $params above)
4243
*
43-
* @throws SerializerException if response body could not be converted into array
44+
* @throws UnexpectedResponseException if response body could not be converted into array
4445
*
4546
* @return array list of issues found
4647
*/
4748
final public function list(array $params = []): array
4849
{
49-
return $this->retrieveData('/issues.json', $params);
50+
try {
51+
return $this->retrieveData('/issues.json', $params);
52+
} catch (SerializerException $th) {
53+
throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th);
54+
}
5055
}
5156

5257
/**
@@ -81,6 +86,10 @@ public function all(array $params = [])
8186
return false;
8287
}
8388

89+
if ($e instanceof UnexpectedResponseException && $e->getPrevious() !== null) {
90+
$e = $e->getPrevious();
91+
}
92+
8493
return $e->getMessage();
8594
}
8695
}

src/Redmine/Api/IssueCategory.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Redmine\Exception\InvalidParameterException;
77
use Redmine\Exception\MissingParameterException;
88
use Redmine\Exception\SerializerException;
9+
use Redmine\Exception\UnexpectedResponseException;
910
use Redmine\Serializer\PathSerializer;
1011
use Redmine\Serializer\XmlSerializer;
1112

@@ -29,7 +30,7 @@ class IssueCategory extends AbstractApi
2930
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
3031
*
3132
* @throws InvalidParameterException if $projectIdentifier is not of type int or string
32-
* @throws SerializerException if response body could not be converted into array
33+
* @throws UnexpectedResponseException if response body could not be converted into array
3334
*
3435
* @return array list of issue categories found
3536
*/
@@ -42,7 +43,11 @@ final public function listByProject($projectIdentifier, array $params = []): arr
4243
));
4344
}
4445

45-
$this->issueCategories = $this->retrieveData('/projects/'.strval($projectIdentifier).'/issue_categories.json', $params);
46+
try {
47+
$this->issueCategories = $this->retrieveData('/projects/'.strval($projectIdentifier).'/issue_categories.json', $params);
48+
} catch (SerializerException $th) {
49+
throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th);
50+
}
4651

4752
return $this->issueCategories;
4853
}
@@ -70,6 +75,10 @@ public function all($project, array $params = [])
7075
return false;
7176
}
7277

78+
if ($e instanceof UnexpectedResponseException && $e->getPrevious() !== null) {
79+
$e = $e->getPrevious();
80+
}
81+
7382
return $e->getMessage();
7483
}
7584
}

src/Redmine/Api/IssuePriority.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Redmine\Exception;
66
use Redmine\Exception\SerializerException;
7+
use Redmine\Exception\UnexpectedResponseException;
78

89
/**
910
* Listing issue priorities.
@@ -23,13 +24,17 @@ class IssuePriority extends AbstractApi
2324
*
2425
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
2526
*
26-
* @throws SerializerException if response body could not be converted into array
27+
* @throws UnexpectedResponseException if response body could not be converted into array
2728
*
2829
* @return array list of issue priorities found
2930
*/
3031
final public function list(array $params = []): array
3132
{
32-
$this->issuePriorities = $this->retrieveData('/enumerations/issue_priorities.json', $params);
33+
try {
34+
$this->issuePriorities = $this->retrieveData('/enumerations/issue_priorities.json', $params);
35+
} catch (SerializerException $th) {
36+
throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th);
37+
}
3338

3439
return $this->issuePriorities;
3540
}
@@ -56,6 +61,10 @@ public function all(array $params = [])
5661
return false;
5762
}
5863

64+
if ($e instanceof UnexpectedResponseException && $e->getPrevious() !== null) {
65+
$e = $e->getPrevious();
66+
}
67+
5968
return $e->getMessage();
6069
}
6170
}

src/Redmine/Api/IssueRelation.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Redmine\Exception;
66
use Redmine\Exception\SerializerException;
7+
use Redmine\Exception\UnexpectedResponseException;
78
use Redmine\Serializer\JsonSerializer;
89

910
/**
@@ -25,13 +26,17 @@ class IssueRelation extends AbstractApi
2526
* @param int $issueId the issue id
2627
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
2728
*
28-
* @throws SerializerException if response body could not be converted into array
29+
* @throws UnexpectedResponseException if response body could not be converted into array
2930
*
3031
* @return array list of relations found
3132
*/
3233
final public function listByIssueId(int $issueId, array $params = []): array
3334
{
34-
$this->relations = $this->retrieveData('/issues/'.strval($issueId).'/relations.json', $params);
35+
try {
36+
$this->relations = $this->retrieveData('/issues/'.strval($issueId).'/relations.json', $params);
37+
} catch (SerializerException $th) {
38+
throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th);
39+
}
3540

3641
return $this->relations;
3742
}
@@ -59,6 +64,10 @@ public function all($issueId, array $params = [])
5964
return false;
6065
}
6166

67+
if ($e instanceof UnexpectedResponseException && $e->getPrevious() !== null) {
68+
$e = $e->getPrevious();
69+
}
70+
6271
return $e->getMessage();
6372
}
6473
}

src/Redmine/Api/IssueStatus.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Redmine\Exception;
66
use Redmine\Exception\SerializerException;
7+
use Redmine\Exception\UnexpectedResponseException;
78

89
/**
910
* Listing issue statuses.
@@ -23,13 +24,17 @@ class IssueStatus extends AbstractApi
2324
*
2425
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
2526
*
26-
* @throws SerializerException if response body could not be converted into array
27+
* @throws UnexpectedResponseException if response body could not be converted into array
2728
*
2829
* @return array list of issue statuses found
2930
*/
3031
final public function list(array $params = []): array
3132
{
32-
$this->issueStatuses = $this->retrieveData('/issue_statuses.json', $params);
33+
try {
34+
$this->issueStatuses = $this->retrieveData('/issue_statuses.json', $params);
35+
} catch (SerializerException $th) {
36+
throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th);
37+
}
3338

3439
return $this->issueStatuses;
3540
}
@@ -56,6 +61,10 @@ public function all(array $params = [])
5661
return false;
5762
}
5863

64+
if ($e instanceof UnexpectedResponseException && $e->getPrevious() !== null) {
65+
$e = $e->getPrevious();
66+
}
67+
5968
return $e->getMessage();
6069
}
6170
}

src/Redmine/Api/Membership.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Redmine\Exception\InvalidParameterException;
77
use Redmine\Exception\MissingParameterException;
88
use Redmine\Exception\SerializerException;
9+
use Redmine\Exception\UnexpectedResponseException;
910
use Redmine\Serializer\XmlSerializer;
1011

1112
/**
@@ -28,7 +29,7 @@ class Membership extends AbstractApi
2829
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
2930
*
3031
* @throws InvalidParameterException if $projectIdentifier is not of type int or string
31-
* @throws SerializerException if response body could not be converted into array
32+
* @throws UnexpectedResponseException if response body could not be converted into array
3233
*
3334
* @return array list of memberships found
3435
*/
@@ -41,7 +42,11 @@ final public function listByProject($projectIdentifier, array $params = []): arr
4142
));
4243
}
4344

44-
$this->memberships = $this->retrieveData('/projects/'.strval($projectIdentifier).'/memberships.json', $params);
45+
try {
46+
$this->memberships = $this->retrieveData('/projects/'.strval($projectIdentifier).'/memberships.json', $params);
47+
} catch (SerializerException $th) {
48+
throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th);
49+
}
4550

4651
return $this->memberships;
4752
}
@@ -69,6 +74,10 @@ public function all($project, array $params = [])
6974
return false;
7075
}
7176

77+
if ($e instanceof UnexpectedResponseException && $e->getPrevious() !== null) {
78+
$e = $e->getPrevious();
79+
}
80+
7281
return $e->getMessage();
7382
}
7483
}

src/Redmine/Api/News.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Redmine\Exception;
66
use Redmine\Exception\InvalidParameterException;
77
use 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

Comments
 (0)