Skip to content

Fix bad 404 received from Imgur #22

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

Merged
merged 2 commits into from
Feb 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 5 additions & 4 deletions lib/Imgur/Api/AlbumOrImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Imgur\Api;

use Imgur\Exception\ErrorException;
use Imgur\Exception\ExceptionInterface;

/**
* This is a special endpoint.
Expand All @@ -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;
}
}
Expand Down
5 changes: 4 additions & 1 deletion lib/Imgur/Middleware/ErrorMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
8 changes: 4 additions & 4 deletions tests/Api/AccountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected function getApiClass()
}

/**
* @expectedException Imgur\Exception\ErrorException
* @expectedException \Imgur\Exception\ErrorException
* @expectedExceptionMessage Authentication required
*/
public function testBaseReal()
Expand Down Expand Up @@ -122,7 +122,7 @@ public function testGalleryFavorites()
}

/**
* @expectedException Imgur\Exception\InvalidArgumentException
* @expectedException \Imgur\Exception\InvalidArgumentException
* @expectedExceptionMessage is wrong. Possible values are
*/
public function testGalleryFavoritesWrongValues()
Expand Down Expand Up @@ -415,7 +415,7 @@ public function testComments()
}

/**
* @expectedException Imgur\Exception\InvalidArgumentException
* @expectedException \Imgur\Exception\InvalidArgumentException
* @expectedExceptionMessage is wrong. Possible values are
*/
public function testCommentsWrongValues()
Expand Down Expand Up @@ -466,7 +466,7 @@ public function testCommentIds()
}

/**
* @expectedException Imgur\Exception\InvalidArgumentException
* @expectedException \Imgur\Exception\InvalidArgumentException
* @expectedExceptionMessage is wrong. Possible values are
*/
public function testCommentIdsWrongValues()
Expand Down
6 changes: 3 additions & 3 deletions tests/Api/AlbumOrImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -92,7 +92,7 @@ public function testWithBadId()
}

/**
* @expectedException Imgur\Exception\ErrorException
* @expectedException \Imgur\Exception\ErrorException
* @expectedExceptionMessage oops
*/
public function testWithImageIdButBadResponse()
Expand Down Expand Up @@ -120,7 +120,7 @@ public function testWithImageIdButBadResponse()
}

/**
* @expectedException Imgur\Exception\ErrorException
* @expectedException \Imgur\Exception\ErrorException
* @expectedExceptionMessage oops
*/
public function testWithAlbumIdButBadResponse()
Expand Down
2 changes: 1 addition & 1 deletion tests/Api/AlbumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected function getApiClass()
}

/**
* @expectedException Imgur\Exception\ErrorException
* @expectedException \Imgur\Exception\ErrorException
* @expectedExceptionMessage Authentication required
*/
public function testBaseReal()
Expand Down
8 changes: 4 additions & 4 deletions tests/Api/CommentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected function getApiClass()
}

/**
* @expectedException Imgur\Exception\ErrorException
* @expectedException \Imgur\Exception\ErrorException
* @expectedExceptionMessage Authentication required
*/
public function testBaseReal()
Expand Down Expand Up @@ -121,7 +121,7 @@ public function testCreate()
}

/**
* @expectedException Imgur\Exception\MissingArgumentException
* @expectedException \Imgur\Exception\MissingArgumentException
* @expectedExceptionMessage parameters is missing
*/
public function testCreateParamMissing()
Expand Down Expand Up @@ -183,7 +183,7 @@ public function testCreateReply()
}

/**
* @expectedException Imgur\Exception\MissingArgumentException
* @expectedException \Imgur\Exception\MissingArgumentException
* @expectedExceptionMessage parameters is missing
*/
public function testCreateReplyParamMissing()
Expand All @@ -209,7 +209,7 @@ public function testVote()
}

/**
* @expectedException Imgur\Exception\InvalidArgumentException
* @expectedException \Imgur\Exception\InvalidArgumentException
* @expectedExceptionMessage is wrong. Possible values are
*/
public function testVoteWrongVoteValue()
Expand Down
4 changes: 2 additions & 2 deletions tests/Api/ConversationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected function getApiClass()
}

/**
* @expectedException Imgur\Exception\ErrorException
* @expectedException \Imgur\Exception\ErrorException
* @expectedExceptionMessage Authentication required
*/
public function testBaseReal()
Expand Down Expand Up @@ -124,7 +124,7 @@ public function testMessageCreate()
}

/**
* @expectedException Imgur\Exception\MissingArgumentException
* @expectedException \Imgur\Exception\MissingArgumentException
* @expectedExceptionMessage parameters is missing
*/
public function testMessageCreateParamMissing()
Expand Down
10 changes: 5 additions & 5 deletions tests/Api/CustomGalleryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected function getApiClass()
}

/**
* @expectedException Imgur\Exception\ErrorException
* @expectedException \Imgur\Exception\ErrorException
* @expectedExceptionMessage Authentication required
*/
public function testBaseReal()
Expand Down Expand Up @@ -115,7 +115,7 @@ public function testCustomGallery()
}

/**
* @expectedException Imgur\Exception\InvalidArgumentException
* @expectedException \Imgur\Exception\InvalidArgumentException
* @expectedExceptionMessage is wrong. Possible values are
*/
public function testCustomGalleryWrongSortValue()
Expand All @@ -124,7 +124,7 @@ public function testCustomGalleryWrongSortValue()
}

/**
* @expectedException Imgur\Exception\InvalidArgumentException
* @expectedException \Imgur\Exception\InvalidArgumentException
* @expectedExceptionMessage is wrong. Possible values are
*/
public function testCustomGalleryWrongWindowValue()
Expand Down Expand Up @@ -152,7 +152,7 @@ public function testFiltered()
}

/**
* @expectedException Imgur\Exception\InvalidArgumentException
* @expectedException \Imgur\Exception\InvalidArgumentException
* @expectedExceptionMessage is wrong. Possible values are
*/
public function testFilteredWrongSortValue()
Expand All @@ -161,7 +161,7 @@ public function testFilteredWrongSortValue()
}

/**
* @expectedException Imgur\Exception\InvalidArgumentException
* @expectedException \Imgur\Exception\InvalidArgumentException
* @expectedExceptionMessage is wrong. Possible values are
*/
public function testFilteredWrongWindowValue()
Expand Down
34 changes: 17 additions & 17 deletions tests/Api/GalleryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected function getApiClass()
}

/**
* @expectedException Imgur\Exception\ErrorException
* @expectedException \Imgur\Exception\ErrorException
* @expectedExceptionMessage Authentication required
*/
public function testBaseReal()
Expand Down Expand Up @@ -132,7 +132,7 @@ public function testGallery()
}

/**
* @expectedException Imgur\Exception\InvalidArgumentException
* @expectedException \Imgur\Exception\InvalidArgumentException
* @expectedExceptionMessage is wrong. Possible values are
*/
public function testGalleryWrongSortValue()
Expand All @@ -141,7 +141,7 @@ public function testGalleryWrongSortValue()
}

/**
* @expectedException Imgur\Exception\InvalidArgumentException
* @expectedException \Imgur\Exception\InvalidArgumentException
* @expectedExceptionMessage is wrong. Possible values are
*/
public function testGalleryWrongSectionValue()
Expand All @@ -150,7 +150,7 @@ public function testGalleryWrongSectionValue()
}

/**
* @expectedException Imgur\Exception\InvalidArgumentException
* @expectedException \Imgur\Exception\InvalidArgumentException
* @expectedExceptionMessage is wrong. Possible values are
*/
public function testGalleryWrongWindowValue()
Expand Down Expand Up @@ -180,7 +180,7 @@ public function testMemesSubgallery()
}

/**
* @expectedException Imgur\Exception\InvalidArgumentException
* @expectedException \Imgur\Exception\InvalidArgumentException
* @expectedExceptionMessage is wrong. Possible values are
*/
public function testMemesSubgalleryWrongSortValue()
Expand All @@ -189,7 +189,7 @@ public function testMemesSubgalleryWrongSortValue()
}

/**
* @expectedException Imgur\Exception\InvalidArgumentException
* @expectedException \Imgur\Exception\InvalidArgumentException
* @expectedExceptionMessage is wrong. Possible values are
*/
public function testMemesSubgalleryWrongWindowValue()
Expand Down Expand Up @@ -238,7 +238,7 @@ public function testSubredditGalleries()
}

/**
* @expectedException Imgur\Exception\InvalidArgumentException
* @expectedException \Imgur\Exception\InvalidArgumentException
* @expectedExceptionMessage is wrong. Possible values are
*/
public function testSubredditGalleriesWrongSortValue()
Expand All @@ -247,7 +247,7 @@ public function testSubredditGalleriesWrongSortValue()
}

/**
* @expectedException Imgur\Exception\InvalidArgumentException
* @expectedException \Imgur\Exception\InvalidArgumentException
* @expectedExceptionMessage is wrong. Possible values are
*/
public function testSubredditGalleriesWrongWindowValue()
Expand Down Expand Up @@ -296,7 +296,7 @@ public function testGalleryTag()
}

/**
* @expectedException Imgur\Exception\InvalidArgumentException
* @expectedException \Imgur\Exception\InvalidArgumentException
* @expectedExceptionMessage is wrong. Possible values are
*/
public function testGalleryTagWrongSortValue()
Expand All @@ -305,7 +305,7 @@ public function testGalleryTagWrongSortValue()
}

/**
* @expectedException Imgur\Exception\InvalidArgumentException
* @expectedException \Imgur\Exception\InvalidArgumentException
* @expectedExceptionMessage is wrong. Possible values are
*/
public function testGalleryTagWrongWindowValue()
Expand Down Expand Up @@ -369,7 +369,7 @@ public function testGalleryVoteTag()
}

/**
* @expectedException Imgur\Exception\InvalidArgumentException
* @expectedException \Imgur\Exception\InvalidArgumentException
* @expectedExceptionMessage is wrong. Possible values are
*/
public function testGalleryVoteTagWrongVoteValue()
Expand Down Expand Up @@ -399,7 +399,7 @@ public function testSearch()
}

/**
* @expectedException Imgur\Exception\InvalidArgumentException
* @expectedException \Imgur\Exception\InvalidArgumentException
* @expectedExceptionMessage is wrong. Possible values are
*/
public function testSearchWrongValues()
Expand Down Expand Up @@ -446,7 +446,7 @@ public function testSubmitToGallery()
}

/**
* @expectedException Imgur\Exception\MissingArgumentException
* @expectedException \Imgur\Exception\MissingArgumentException
* @expectedExceptionMessage parameters is missing
*/
public function testSubmitToGalleryParamMissing()
Expand Down Expand Up @@ -563,7 +563,7 @@ public function testVote()
}

/**
* @expectedException Imgur\Exception\InvalidArgumentException
* @expectedException \Imgur\Exception\InvalidArgumentException
* @expectedExceptionMessage is wrong. Possible values are
*/
public function testVoteWrongVoteValue()
Expand Down Expand Up @@ -593,7 +593,7 @@ public function testComments()
}

/**
* @expectedException Imgur\Exception\InvalidArgumentException
* @expectedException \Imgur\Exception\InvalidArgumentException
* @expectedExceptionMessage is wrong. Possible values are
*/
public function testCommentsWrongValues()
Expand Down Expand Up @@ -638,7 +638,7 @@ public function testCreateComment()
}

/**
* @expectedException Imgur\Exception\MissingArgumentException
* @expectedException \Imgur\Exception\MissingArgumentException
* @expectedExceptionMessage parameters is missing
*/
public function testCreateCommentParamMissing()
Expand All @@ -664,7 +664,7 @@ public function testCreateReply()
}

/**
* @expectedException Imgur\Exception\MissingArgumentException
* @expectedException \Imgur\Exception\MissingArgumentException
* @expectedExceptionMessage parameters is missing
*/
public function testCreateReplyParamMissing()
Expand Down
6 changes: 3 additions & 3 deletions tests/Api/ImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected function getApiClass()
}

/**
* @expectedException Imgur\Exception\ErrorException
* @expectedException \Imgur\Exception\ErrorException
* @expectedExceptionMessage Authentication required
*/
public function testBaseReal()
Expand Down Expand Up @@ -150,7 +150,7 @@ public function testUploadWithFile()
}

/**
* @expectedException Imgur\Exception\InvalidArgumentException
* @expectedException \Imgur\Exception\InvalidArgumentException
* @expectedExceptionMessage is wrong. Possible values are
*/
public function testUploadWithBadType()
Expand All @@ -159,7 +159,7 @@ public function testUploadWithBadType()
}

/**
* @expectedException Imgur\Exception\MissingArgumentException
* @expectedException \Imgur\Exception\MissingArgumentException
* @expectedExceptionMessage parameters is missing
*/
public function testUploadWithUrlParamMissing()
Expand Down
Loading