diff --git a/lib/Imgur/Api/AlbumOrImage.php b/lib/Imgur/Api/AlbumOrImage.php index b6a579f..c10830e 100644 --- a/lib/Imgur/Api/AlbumOrImage.php +++ b/lib/Imgur/Api/AlbumOrImage.php @@ -3,6 +3,7 @@ namespace Imgur\Api; use Imgur\Exception\ErrorException; +use Imgur\Exception\ExceptionInterface; /** * This is a special endpoint. @@ -22,16 +23,16 @@ public function find($imageIdOrAlbumId) { try { return $this->get('image/' . $imageIdOrAlbumId); - } catch (ErrorException $e) { - if (false === strpos($e->getMessage(), 'Unable to find an image with the id')) { + } catch (ExceptionInterface $e) { + if ($e->getCode() !== 404) { throw $e; } } try { return $this->get('album/' . $imageIdOrAlbumId); - } catch (ErrorException $e) { - if (false === strpos($e->getMessage(), 'Unable to find an album with the id')) { + } catch (ExceptionInterface $e) { + if ($e->getCode() !== 404) { throw $e; } } diff --git a/lib/Imgur/Middleware/ErrorMiddleware.php b/lib/Imgur/Middleware/ErrorMiddleware.php index ffd1518..6c8b770 100644 --- a/lib/Imgur/Middleware/ErrorMiddleware.php +++ b/lib/Imgur/Middleware/ErrorMiddleware.php @@ -71,7 +71,10 @@ public function checkError(ResponseInterface $response) } if (is_array($responseData) && isset($responseData['data']) && isset($responseData['data']['error'])) { - throw new ErrorException('Request to: ' . $responseData['data']['request'] . ' failed with: "' . $responseData['data']['error'] . '"'); + throw new ErrorException( + 'Request to: ' . $responseData['data']['request'] . ' failed with: "' . $responseData['data']['error'] . '"', + $response->getStatusCode() + ); } throw new RuntimeException(is_array($responseData) && isset($responseData['message']) ? $responseData['message'] : $responseData, $response->getStatusCode()); diff --git a/tests/Api/AccountTest.php b/tests/Api/AccountTest.php index 8e2cd01..57ce3d6 100644 --- a/tests/Api/AccountTest.php +++ b/tests/Api/AccountTest.php @@ -18,7 +18,7 @@ protected function getApiClass() } /** - * @expectedException Imgur\Exception\ErrorException + * @expectedException \Imgur\Exception\ErrorException * @expectedExceptionMessage Authentication required */ public function testBaseReal() @@ -122,7 +122,7 @@ public function testGalleryFavorites() } /** - * @expectedException Imgur\Exception\InvalidArgumentException + * @expectedException \Imgur\Exception\InvalidArgumentException * @expectedExceptionMessage is wrong. Possible values are */ public function testGalleryFavoritesWrongValues() @@ -415,7 +415,7 @@ public function testComments() } /** - * @expectedException Imgur\Exception\InvalidArgumentException + * @expectedException \Imgur\Exception\InvalidArgumentException * @expectedExceptionMessage is wrong. Possible values are */ public function testCommentsWrongValues() @@ -466,7 +466,7 @@ public function testCommentIds() } /** - * @expectedException Imgur\Exception\InvalidArgumentException + * @expectedException \Imgur\Exception\InvalidArgumentException * @expectedExceptionMessage is wrong. Possible values are */ public function testCommentIdsWrongValues() diff --git a/tests/Api/AlbumOrImageTest.php b/tests/Api/AlbumOrImageTest.php index 1dd8db4..4addffb 100644 --- a/tests/Api/AlbumOrImageTest.php +++ b/tests/Api/AlbumOrImageTest.php @@ -55,7 +55,7 @@ public function testWithAlbumId() } /** - * @expectedException Imgur\Exception\ErrorException + * @expectedException \Imgur\Exception\ErrorException * @expectedExceptionMessage Unable to find an album OR an image with the id */ public function testWithBadId() @@ -92,7 +92,7 @@ public function testWithBadId() } /** - * @expectedException Imgur\Exception\ErrorException + * @expectedException \Imgur\Exception\ErrorException * @expectedExceptionMessage oops */ public function testWithImageIdButBadResponse() @@ -120,7 +120,7 @@ public function testWithImageIdButBadResponse() } /** - * @expectedException Imgur\Exception\ErrorException + * @expectedException \Imgur\Exception\ErrorException * @expectedExceptionMessage oops */ public function testWithAlbumIdButBadResponse() diff --git a/tests/Api/AlbumTest.php b/tests/Api/AlbumTest.php index 7c350a4..41e5187 100644 --- a/tests/Api/AlbumTest.php +++ b/tests/Api/AlbumTest.php @@ -18,7 +18,7 @@ protected function getApiClass() } /** - * @expectedException Imgur\Exception\ErrorException + * @expectedException \Imgur\Exception\ErrorException * @expectedExceptionMessage Authentication required */ public function testBaseReal() diff --git a/tests/Api/CommentTest.php b/tests/Api/CommentTest.php index e51461b..027611c 100644 --- a/tests/Api/CommentTest.php +++ b/tests/Api/CommentTest.php @@ -18,7 +18,7 @@ protected function getApiClass() } /** - * @expectedException Imgur\Exception\ErrorException + * @expectedException \Imgur\Exception\ErrorException * @expectedExceptionMessage Authentication required */ public function testBaseReal() @@ -121,7 +121,7 @@ public function testCreate() } /** - * @expectedException Imgur\Exception\MissingArgumentException + * @expectedException \Imgur\Exception\MissingArgumentException * @expectedExceptionMessage parameters is missing */ public function testCreateParamMissing() @@ -183,7 +183,7 @@ public function testCreateReply() } /** - * @expectedException Imgur\Exception\MissingArgumentException + * @expectedException \Imgur\Exception\MissingArgumentException * @expectedExceptionMessage parameters is missing */ public function testCreateReplyParamMissing() @@ -209,7 +209,7 @@ public function testVote() } /** - * @expectedException Imgur\Exception\InvalidArgumentException + * @expectedException \Imgur\Exception\InvalidArgumentException * @expectedExceptionMessage is wrong. Possible values are */ public function testVoteWrongVoteValue() diff --git a/tests/Api/ConversationTest.php b/tests/Api/ConversationTest.php index 74c5ce1..66f17c1 100644 --- a/tests/Api/ConversationTest.php +++ b/tests/Api/ConversationTest.php @@ -18,7 +18,7 @@ protected function getApiClass() } /** - * @expectedException Imgur\Exception\ErrorException + * @expectedException \Imgur\Exception\ErrorException * @expectedExceptionMessage Authentication required */ public function testBaseReal() @@ -124,7 +124,7 @@ public function testMessageCreate() } /** - * @expectedException Imgur\Exception\MissingArgumentException + * @expectedException \Imgur\Exception\MissingArgumentException * @expectedExceptionMessage parameters is missing */ public function testMessageCreateParamMissing() diff --git a/tests/Api/CustomGalleryTest.php b/tests/Api/CustomGalleryTest.php index 4d7c065..80bff91 100644 --- a/tests/Api/CustomGalleryTest.php +++ b/tests/Api/CustomGalleryTest.php @@ -18,7 +18,7 @@ protected function getApiClass() } /** - * @expectedException Imgur\Exception\ErrorException + * @expectedException \Imgur\Exception\ErrorException * @expectedExceptionMessage Authentication required */ public function testBaseReal() @@ -115,7 +115,7 @@ public function testCustomGallery() } /** - * @expectedException Imgur\Exception\InvalidArgumentException + * @expectedException \Imgur\Exception\InvalidArgumentException * @expectedExceptionMessage is wrong. Possible values are */ public function testCustomGalleryWrongSortValue() @@ -124,7 +124,7 @@ public function testCustomGalleryWrongSortValue() } /** - * @expectedException Imgur\Exception\InvalidArgumentException + * @expectedException \Imgur\Exception\InvalidArgumentException * @expectedExceptionMessage is wrong. Possible values are */ public function testCustomGalleryWrongWindowValue() @@ -152,7 +152,7 @@ public function testFiltered() } /** - * @expectedException Imgur\Exception\InvalidArgumentException + * @expectedException \Imgur\Exception\InvalidArgumentException * @expectedExceptionMessage is wrong. Possible values are */ public function testFilteredWrongSortValue() @@ -161,7 +161,7 @@ public function testFilteredWrongSortValue() } /** - * @expectedException Imgur\Exception\InvalidArgumentException + * @expectedException \Imgur\Exception\InvalidArgumentException * @expectedExceptionMessage is wrong. Possible values are */ public function testFilteredWrongWindowValue() diff --git a/tests/Api/GalleryTest.php b/tests/Api/GalleryTest.php index 3cbc589..eeeb4a4 100644 --- a/tests/Api/GalleryTest.php +++ b/tests/Api/GalleryTest.php @@ -18,7 +18,7 @@ protected function getApiClass() } /** - * @expectedException Imgur\Exception\ErrorException + * @expectedException \Imgur\Exception\ErrorException * @expectedExceptionMessage Authentication required */ public function testBaseReal() @@ -132,7 +132,7 @@ public function testGallery() } /** - * @expectedException Imgur\Exception\InvalidArgumentException + * @expectedException \Imgur\Exception\InvalidArgumentException * @expectedExceptionMessage is wrong. Possible values are */ public function testGalleryWrongSortValue() @@ -141,7 +141,7 @@ public function testGalleryWrongSortValue() } /** - * @expectedException Imgur\Exception\InvalidArgumentException + * @expectedException \Imgur\Exception\InvalidArgumentException * @expectedExceptionMessage is wrong. Possible values are */ public function testGalleryWrongSectionValue() @@ -150,7 +150,7 @@ public function testGalleryWrongSectionValue() } /** - * @expectedException Imgur\Exception\InvalidArgumentException + * @expectedException \Imgur\Exception\InvalidArgumentException * @expectedExceptionMessage is wrong. Possible values are */ public function testGalleryWrongWindowValue() @@ -180,7 +180,7 @@ public function testMemesSubgallery() } /** - * @expectedException Imgur\Exception\InvalidArgumentException + * @expectedException \Imgur\Exception\InvalidArgumentException * @expectedExceptionMessage is wrong. Possible values are */ public function testMemesSubgalleryWrongSortValue() @@ -189,7 +189,7 @@ public function testMemesSubgalleryWrongSortValue() } /** - * @expectedException Imgur\Exception\InvalidArgumentException + * @expectedException \Imgur\Exception\InvalidArgumentException * @expectedExceptionMessage is wrong. Possible values are */ public function testMemesSubgalleryWrongWindowValue() @@ -238,7 +238,7 @@ public function testSubredditGalleries() } /** - * @expectedException Imgur\Exception\InvalidArgumentException + * @expectedException \Imgur\Exception\InvalidArgumentException * @expectedExceptionMessage is wrong. Possible values are */ public function testSubredditGalleriesWrongSortValue() @@ -247,7 +247,7 @@ public function testSubredditGalleriesWrongSortValue() } /** - * @expectedException Imgur\Exception\InvalidArgumentException + * @expectedException \Imgur\Exception\InvalidArgumentException * @expectedExceptionMessage is wrong. Possible values are */ public function testSubredditGalleriesWrongWindowValue() @@ -296,7 +296,7 @@ public function testGalleryTag() } /** - * @expectedException Imgur\Exception\InvalidArgumentException + * @expectedException \Imgur\Exception\InvalidArgumentException * @expectedExceptionMessage is wrong. Possible values are */ public function testGalleryTagWrongSortValue() @@ -305,7 +305,7 @@ public function testGalleryTagWrongSortValue() } /** - * @expectedException Imgur\Exception\InvalidArgumentException + * @expectedException \Imgur\Exception\InvalidArgumentException * @expectedExceptionMessage is wrong. Possible values are */ public function testGalleryTagWrongWindowValue() @@ -369,7 +369,7 @@ public function testGalleryVoteTag() } /** - * @expectedException Imgur\Exception\InvalidArgumentException + * @expectedException \Imgur\Exception\InvalidArgumentException * @expectedExceptionMessage is wrong. Possible values are */ public function testGalleryVoteTagWrongVoteValue() @@ -399,7 +399,7 @@ public function testSearch() } /** - * @expectedException Imgur\Exception\InvalidArgumentException + * @expectedException \Imgur\Exception\InvalidArgumentException * @expectedExceptionMessage is wrong. Possible values are */ public function testSearchWrongValues() @@ -446,7 +446,7 @@ public function testSubmitToGallery() } /** - * @expectedException Imgur\Exception\MissingArgumentException + * @expectedException \Imgur\Exception\MissingArgumentException * @expectedExceptionMessage parameters is missing */ public function testSubmitToGalleryParamMissing() @@ -563,7 +563,7 @@ public function testVote() } /** - * @expectedException Imgur\Exception\InvalidArgumentException + * @expectedException \Imgur\Exception\InvalidArgumentException * @expectedExceptionMessage is wrong. Possible values are */ public function testVoteWrongVoteValue() @@ -593,7 +593,7 @@ public function testComments() } /** - * @expectedException Imgur\Exception\InvalidArgumentException + * @expectedException \Imgur\Exception\InvalidArgumentException * @expectedExceptionMessage is wrong. Possible values are */ public function testCommentsWrongValues() @@ -638,7 +638,7 @@ public function testCreateComment() } /** - * @expectedException Imgur\Exception\MissingArgumentException + * @expectedException \Imgur\Exception\MissingArgumentException * @expectedExceptionMessage parameters is missing */ public function testCreateCommentParamMissing() @@ -664,7 +664,7 @@ public function testCreateReply() } /** - * @expectedException Imgur\Exception\MissingArgumentException + * @expectedException \Imgur\Exception\MissingArgumentException * @expectedExceptionMessage parameters is missing */ public function testCreateReplyParamMissing() diff --git a/tests/Api/ImageTest.php b/tests/Api/ImageTest.php index 5d40902..c1c1de7 100644 --- a/tests/Api/ImageTest.php +++ b/tests/Api/ImageTest.php @@ -18,7 +18,7 @@ protected function getApiClass() } /** - * @expectedException Imgur\Exception\ErrorException + * @expectedException \Imgur\Exception\ErrorException * @expectedExceptionMessage Authentication required */ public function testBaseReal() @@ -150,7 +150,7 @@ public function testUploadWithFile() } /** - * @expectedException Imgur\Exception\InvalidArgumentException + * @expectedException \Imgur\Exception\InvalidArgumentException * @expectedExceptionMessage is wrong. Possible values are */ public function testUploadWithBadType() @@ -159,7 +159,7 @@ public function testUploadWithBadType() } /** - * @expectedException Imgur\Exception\MissingArgumentException + * @expectedException \Imgur\Exception\MissingArgumentException * @expectedExceptionMessage parameters is missing */ public function testUploadWithUrlParamMissing() diff --git a/tests/Api/MemegenTest.php b/tests/Api/MemegenTest.php index 028c607..e806e50 100644 --- a/tests/Api/MemegenTest.php +++ b/tests/Api/MemegenTest.php @@ -18,7 +18,7 @@ protected function getApiClass() } /** - * @expectedException Imgur\Exception\ErrorException + * @expectedException \Imgur\Exception\ErrorException * @expectedExceptionMessage Authentication required */ public function testBaseReal() diff --git a/tests/Api/NotificationTest.php b/tests/Api/NotificationTest.php index 1bdbf2d..17c4ef2 100644 --- a/tests/Api/NotificationTest.php +++ b/tests/Api/NotificationTest.php @@ -18,7 +18,7 @@ protected function getApiClass() } /** - * @expectedException Imgur\Exception\ErrorException + * @expectedException \Imgur\Exception\ErrorException * @expectedExceptionMessage Authentication required */ public function testBaseReal() diff --git a/tests/Api/TopicTest.php b/tests/Api/TopicTest.php index 1289b0d..66c2254 100644 --- a/tests/Api/TopicTest.php +++ b/tests/Api/TopicTest.php @@ -18,7 +18,7 @@ protected function getApiClass() } /** - * @expectedException Imgur\Exception\ErrorException + * @expectedException \Imgur\Exception\ErrorException * @expectedExceptionMessage Authentication required */ public function testBaseReal() @@ -169,7 +169,7 @@ public function testGalleryTopic() } /** - * @expectedException Imgur\Exception\InvalidArgumentException + * @expectedException \Imgur\Exception\InvalidArgumentException * @expectedExceptionMessage is wrong. Possible values are */ public function testGalleryTopicWrongSortValue() @@ -178,7 +178,7 @@ public function testGalleryTopicWrongSortValue() } /** - * @expectedException Imgur\Exception\InvalidArgumentException + * @expectedException \Imgur\Exception\InvalidArgumentException * @expectedExceptionMessage is wrong. Possible values are */ public function testGalleryTopicWrongWindowValue()