Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new UnexpectedResponseException #340

Merged
merged 24 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
633fee9
Create UnexpectedResponseException, throw it in CustomField::list()
Art4 Dec 22, 2023
fabd847
Update exception message
Art4 Dec 28, 2023
297fe43
Merge branch 'v2.x' into 339-add-new-exception-on-unexpected-response
Art4 Dec 28, 2023
cfa3527
Fix tests
Art4 Dec 28, 2023
dccdc9c
let Group::all() throw UnexpectedResponseException
Art4 Dec 28, 2023
5de49d4
let Issue::list() throw UnexpectedResponseException
Art4 Dec 28, 2023
f269a5b
Speed up deprecated all() methods a little bit
Art4 Dec 28, 2023
d29c098
let IssueCategory::listByProject() throw UnexpectedResponseException
Art4 Dec 28, 2023
fa925b7
let IssuePriority::list() throw UnexpectedResponseException
Art4 Dec 28, 2023
01c8d83
let IssueRelation::listByIssueId() throw UnexpectedResponseException
Art4 Dec 28, 2023
6f66eef
let IssueStatus::list() throw UnexpectedResponseException
Art4 Dec 28, 2023
6508e1f
let Membership::listByProject() throw UnexpectedResponseException
Art4 Dec 28, 2023
9780ffb
let News::list() and News::listByProject() throw UnexpectedResponseEx…
Art4 Dec 29, 2023
4b984d3
let Project::list() throw UnexpectedResponseException
Art4 Dec 29, 2023
13c5a5c
let Query::list() throw UnexpectedResponseException
Art4 Dec 29, 2023
71e5a95
let Role::list() throw UnexpectedResponseException
Art4 Dec 29, 2023
7598de5
let Search::listByQuery() throw UnexpectedResponseException
Art4 Dec 29, 2023
22d83e7
let TimeEntry::list() throw UnexpectedResponseException
Art4 Dec 29, 2023
f19e9ee
let TimeEntryActivity::list() throw UnexpectedResponseException
Art4 Dec 29, 2023
3791ccc
let Tracker::list() throw UnexpectedResponseException
Art4 Dec 30, 2023
404af8c
let User::list() throw UnexpectedResponseException
Art4 Dec 30, 2023
6332525
let Version::listByProject() throw UnexpectedResponseException
Art4 Dec 30, 2023
06c6897
let Wiki::listByProject() throw UnexpectedResponseException
Art4 Dec 30, 2023
ec0296e
Update CHANGELOG.md
Art4 Dec 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,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