Skip to content

Commit

Permalink
Merge pull request #340 from Art4/339-add-new-exception-on-unexpected…
Browse files Browse the repository at this point in the history
…-response

Add new UnexpectedResponseException
  • Loading branch information
Art4 authored Jan 3, 2024
2 parents cd10480 + ec0296e commit c132efc
Show file tree
Hide file tree
Showing 41 changed files with 756 additions and 40 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- New method `Redmine\Api\User::list()` to list users.
- New method `Redmine\Api\Version::listByProject()` to list versions from a project.
- New method `Redmine\Api\Wiki::listByProject()` to list wiki pages from a project.
- New exception `Redmine\Exception\UnexpectedResponseException` if the Redmine server responded with an unexpected body.

### Deprecated

Expand Down
13 changes: 11 additions & 2 deletions src/Redmine/Api/CustomField.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Redmine\Exception;
use Redmine\Exception\SerializerException;
use Redmine\Exception\UnexpectedResponseException;

/**
* Listing custom fields.
Expand All @@ -23,13 +24,17 @@ class CustomField extends AbstractApi
*
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
*
* @throws SerializerException if response body could not be converted into array
* @throws UnexpectedResponseException if response body could not be converted into array
*
* @return array list of custom fields found
*/
final public function list(array $params = []): array
{
$this->customFields = $this->retrieveData('/custom_fields.json', $params);
try {
$this->customFields = $this->retrieveData('/custom_fields.json', $params);
} catch (SerializerException $th) {
throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th);
}

return $this->customFields;
}
Expand All @@ -56,6 +61,10 @@ public function all(array $params = [])
return false;
}

if ($e instanceof UnexpectedResponseException && $e->getPrevious() !== null) {
$e = $e->getPrevious();
}

return $e->getMessage();
}
}
Expand Down
13 changes: 11 additions & 2 deletions src/Redmine/Api/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Redmine\Exception;
use Redmine\Exception\MissingParameterException;
use Redmine\Exception\SerializerException;
use Redmine\Exception\UnexpectedResponseException;
use Redmine\Serializer\PathSerializer;
use Redmine\Serializer\XmlSerializer;

Expand All @@ -26,13 +27,17 @@ class Group extends AbstractApi
*
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
*
* @throws SerializerException if response body could not be converted into array
* @throws UnexpectedResponseException if response body could not be converted into array
*
* @return array list of groups found
*/
final public function list(array $params = []): array
{
$this->groups = $this->retrieveData('/groups.json', $params);
try {
$this->groups = $this->retrieveData('/groups.json', $params);
} catch (SerializerException $th) {
throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th);
}

return $this->groups;
}
Expand All @@ -59,6 +64,10 @@ public function all(array $params = [])
return false;
}

if ($e instanceof UnexpectedResponseException && $e->getPrevious() !== null) {
$e = $e->getPrevious();
}

return $e->getMessage();
}
}
Expand Down
13 changes: 11 additions & 2 deletions src/Redmine/Api/Issue.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Redmine\Exception;
use Redmine\Exception\SerializerException;
use Redmine\Exception\UnexpectedResponseException;
use Redmine\Serializer\JsonSerializer;
use Redmine\Serializer\PathSerializer;
use Redmine\Serializer\XmlSerializer;
Expand Down Expand Up @@ -40,13 +41,17 @@ class Issue extends AbstractApi
*
* @param array $params the additional parameters (cf available $params above)
*
* @throws SerializerException if response body could not be converted into array
* @throws UnexpectedResponseException if response body could not be converted into array
*
* @return array list of issues found
*/
final public function list(array $params = []): array
{
return $this->retrieveData('/issues.json', $params);
try {
return $this->retrieveData('/issues.json', $params);
} catch (SerializerException $th) {
throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th);
}
}

/**
Expand Down Expand Up @@ -81,6 +86,10 @@ public function all(array $params = [])
return false;
}

if ($e instanceof UnexpectedResponseException && $e->getPrevious() !== null) {
$e = $e->getPrevious();
}

return $e->getMessage();
}
}
Expand Down
13 changes: 11 additions & 2 deletions src/Redmine/Api/IssueCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Redmine\Exception\InvalidParameterException;
use Redmine\Exception\MissingParameterException;
use Redmine\Exception\SerializerException;
use Redmine\Exception\UnexpectedResponseException;
use Redmine\Serializer\PathSerializer;
use Redmine\Serializer\XmlSerializer;

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

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

return $this->issueCategories;
}
Expand Down Expand Up @@ -70,6 +75,10 @@ public function all($project, array $params = [])
return false;
}

if ($e instanceof UnexpectedResponseException && $e->getPrevious() !== null) {
$e = $e->getPrevious();
}

return $e->getMessage();
}
}
Expand Down
13 changes: 11 additions & 2 deletions src/Redmine/Api/IssuePriority.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Redmine\Exception;
use Redmine\Exception\SerializerException;
use Redmine\Exception\UnexpectedResponseException;

/**
* Listing issue priorities.
Expand All @@ -23,13 +24,17 @@ class IssuePriority extends AbstractApi
*
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
*
* @throws SerializerException if response body could not be converted into array
* @throws UnexpectedResponseException if response body could not be converted into array
*
* @return array list of issue priorities found
*/
final public function list(array $params = []): array
{
$this->issuePriorities = $this->retrieveData('/enumerations/issue_priorities.json', $params);
try {
$this->issuePriorities = $this->retrieveData('/enumerations/issue_priorities.json', $params);
} catch (SerializerException $th) {
throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th);
}

return $this->issuePriorities;
}
Expand All @@ -56,6 +61,10 @@ public function all(array $params = [])
return false;
}

if ($e instanceof UnexpectedResponseException && $e->getPrevious() !== null) {
$e = $e->getPrevious();
}

return $e->getMessage();
}
}
Expand Down
13 changes: 11 additions & 2 deletions src/Redmine/Api/IssueRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Redmine\Exception;
use Redmine\Exception\SerializerException;
use Redmine\Exception\UnexpectedResponseException;
use Redmine\Serializer\JsonSerializer;

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

return $this->relations;
}
Expand Down Expand Up @@ -59,6 +64,10 @@ public function all($issueId, array $params = [])
return false;
}

if ($e instanceof UnexpectedResponseException && $e->getPrevious() !== null) {
$e = $e->getPrevious();
}

return $e->getMessage();
}
}
Expand Down
13 changes: 11 additions & 2 deletions src/Redmine/Api/IssueStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Redmine\Exception;
use Redmine\Exception\SerializerException;
use Redmine\Exception\UnexpectedResponseException;

/**
* Listing issue statuses.
Expand All @@ -23,13 +24,17 @@ class IssueStatus extends AbstractApi
*
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
*
* @throws SerializerException if response body could not be converted into array
* @throws UnexpectedResponseException if response body could not be converted into array
*
* @return array list of issue statuses found
*/
final public function list(array $params = []): array
{
$this->issueStatuses = $this->retrieveData('/issue_statuses.json', $params);
try {
$this->issueStatuses = $this->retrieveData('/issue_statuses.json', $params);
} catch (SerializerException $th) {
throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th);
}

return $this->issueStatuses;
}
Expand All @@ -56,6 +61,10 @@ public function all(array $params = [])
return false;
}

if ($e instanceof UnexpectedResponseException && $e->getPrevious() !== null) {
$e = $e->getPrevious();
}

return $e->getMessage();
}
}
Expand Down
13 changes: 11 additions & 2 deletions src/Redmine/Api/Membership.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Redmine\Exception\InvalidParameterException;
use Redmine\Exception\MissingParameterException;
use Redmine\Exception\SerializerException;
use Redmine\Exception\UnexpectedResponseException;
use Redmine\Serializer\XmlSerializer;

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

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

return $this->memberships;
}
Expand Down Expand Up @@ -69,6 +74,10 @@ public function all($project, array $params = [])
return false;
}

if ($e instanceof UnexpectedResponseException && $e->getPrevious() !== null) {
$e = $e->getPrevious();
}

return $e->getMessage();
}
}
Expand Down
21 changes: 17 additions & 4 deletions src/Redmine/Api/News.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Redmine\Exception;
use Redmine\Exception\InvalidParameterException;
use Redmine\Exception\SerializerException;
use Redmine\Exception\UnexpectedResponseException;

/**
* @see http://www.redmine.org/projects/redmine/wiki/Rest_News
Expand All @@ -24,7 +25,7 @@ class News extends AbstractApi
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
*
* @throws InvalidParameterException if $projectIdentifier is not of type int or string
* @throws SerializerException if response body could not be converted into array
* @throws UnexpectedResponseException if response body could not be converted into array
*
* @return array list of news found
*/
Expand All @@ -37,7 +38,11 @@ final public function listByProject($projectIdentifier, array $params = []): arr
));
}

$this->news = $this->retrieveData('/projects/'.strval($projectIdentifier).'/news.json', $params);
try {
$this->news = $this->retrieveData('/projects/'.strval($projectIdentifier).'/news.json', $params);
} catch (SerializerException $th) {
throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th);
}

return $this->news;
}
Expand All @@ -49,13 +54,17 @@ final public function listByProject($projectIdentifier, array $params = []): arr
*
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
*
* @throws SerializerException if response body could not be converted into array
* @throws UnexpectedResponseException if response body could not be converted into array
*
* @return array list of news found
*/
final public function list(array $params = []): array
{
$this->news = $this->retrieveData('/news.json', $params);
try {
$this->news = $this->retrieveData('/news.json', $params);
} catch (SerializerException $th) {
throw new UnexpectedResponseException('The Redmine server responded with an unexpected body.', $th->getCode(), $th);
}

return $this->news;
}
Expand Down Expand Up @@ -87,6 +96,10 @@ public function all($project = null, array $params = [])
return false;
}

if ($e instanceof UnexpectedResponseException && $e->getPrevious() !== null) {
$e = $e->getPrevious();
}

return $e->getMessage();
}
}
Expand Down
Loading

0 comments on commit c132efc

Please sign in to comment.