Skip to content

Commit 9c1dd84

Browse files
authored
Merge pull request #21 from j0k3r/2-bad-imgur-404
Fix bad 404 received from Imgur
2 parents 2027e89 + 66248a9 commit 9c1dd84

14 files changed

+54
-50
lines changed

lib/Imgur/Api/AlbumOrImage.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Imgur\Api;
44

55
use Imgur\Exception\ErrorException;
6+
use Imgur\Exception\ExceptionInterface;
67

78
/**
89
* This is a special endpoint.
@@ -22,16 +23,16 @@ public function find($imageIdOrAlbumId)
2223
{
2324
try {
2425
return $this->get('image/' . $imageIdOrAlbumId);
25-
} catch (ErrorException $e) {
26-
if (false === strpos($e->getMessage(), 'Unable to find an image with the id')) {
26+
} catch (ExceptionInterface $e) {
27+
if ($e->getCode() !== 404) {
2728
throw $e;
2829
}
2930
}
3031

3132
try {
3233
return $this->get('album/' . $imageIdOrAlbumId);
33-
} catch (ErrorException $e) {
34-
if (false === strpos($e->getMessage(), 'Unable to find an album with the id')) {
34+
} catch (ExceptionInterface $e) {
35+
if ($e->getCode() !== 404) {
3536
throw $e;
3637
}
3738
}

lib/Imgur/Listener/ErrorListener.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ public function error(ErrorEvent $event)
3333
}
3434

3535
if (is_array($responseData) && isset($responseData['data']) && isset($responseData['data']['error'])) {
36-
throw new ErrorException('Request to: ' . $responseData['data']['request'] . ' failed with: "' . $responseData['data']['error'] . '"');
36+
throw new ErrorException(
37+
'Request to: ' . $responseData['data']['request'] . ' failed with: "' . $responseData['data']['error'] . '"',
38+
$response->getStatusCode()
39+
);
3740
}
3841

3942
throw new RuntimeException(is_array($responseData) && isset($responseData['message']) ? $responseData['message'] : $responseData, $response->getStatusCode());

tests/Api/AccountTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ protected function getApiClass()
1818
}
1919

2020
/**
21-
* @expectedException Imgur\Exception\ErrorException
21+
* @expectedException \Imgur\Exception\ErrorException
2222
* @expectedExceptionMessage Authentication required
2323
*/
2424
public function testBaseReal()
@@ -122,7 +122,7 @@ public function testGalleryFavorites()
122122
}
123123

124124
/**
125-
* @expectedException Imgur\Exception\InvalidArgumentException
125+
* @expectedException \Imgur\Exception\InvalidArgumentException
126126
* @expectedExceptionMessage is wrong. Possible values are
127127
*/
128128
public function testGalleryFavoritesWrongValues()
@@ -415,7 +415,7 @@ public function testComments()
415415
}
416416

417417
/**
418-
* @expectedException Imgur\Exception\InvalidArgumentException
418+
* @expectedException \Imgur\Exception\InvalidArgumentException
419419
* @expectedExceptionMessage is wrong. Possible values are
420420
*/
421421
public function testCommentsWrongValues()
@@ -466,7 +466,7 @@ public function testCommentIds()
466466
}
467467

468468
/**
469-
* @expectedException Imgur\Exception\InvalidArgumentException
469+
* @expectedException \Imgur\Exception\InvalidArgumentException
470470
* @expectedExceptionMessage is wrong. Possible values are
471471
*/
472472
public function testCommentIdsWrongValues()

tests/Api/AlbumOrImageTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function testWithAlbumId()
5454
}
5555

5656
/**
57-
* @expectedException Imgur\Exception\ErrorException
57+
* @expectedException \Imgur\Exception\ErrorException
5858
* @expectedExceptionMessage Unable to find an album OR an image with the id
5959
*/
6060
public function testWithBadId()
@@ -91,7 +91,7 @@ public function testWithBadId()
9191
}
9292

9393
/**
94-
* @expectedException Imgur\Exception\ErrorException
94+
* @expectedException \Imgur\Exception\ErrorException
9595
* @expectedExceptionMessage oops
9696
*/
9797
public function testWithImageIdButBadResponse()
@@ -119,7 +119,7 @@ public function testWithImageIdButBadResponse()
119119
}
120120

121121
/**
122-
* @expectedException Imgur\Exception\ErrorException
122+
* @expectedException \Imgur\Exception\ErrorException
123123
* @expectedExceptionMessage oops
124124
*/
125125
public function testWithAlbumIdButBadResponse()

tests/Api/AlbumTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ protected function getApiClass()
1818
}
1919

2020
/**
21-
* @expectedException Imgur\Exception\ErrorException
21+
* @expectedException \Imgur\Exception\ErrorException
2222
* @expectedExceptionMessage Authentication required
2323
*/
2424
public function testBaseReal()

tests/Api/CommentTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ protected function getApiClass()
1818
}
1919

2020
/**
21-
* @expectedException Imgur\Exception\ErrorException
21+
* @expectedException \Imgur\Exception\ErrorException
2222
* @expectedExceptionMessage Authentication required
2323
*/
2424
public function testBaseReal()
@@ -121,7 +121,7 @@ public function testCreate()
121121
}
122122

123123
/**
124-
* @expectedException Imgur\Exception\MissingArgumentException
124+
* @expectedException \Imgur\Exception\MissingArgumentException
125125
* @expectedExceptionMessage parameters is missing
126126
*/
127127
public function testCreateParamMissing()
@@ -183,7 +183,7 @@ public function testCreateReply()
183183
}
184184

185185
/**
186-
* @expectedException Imgur\Exception\MissingArgumentException
186+
* @expectedException \Imgur\Exception\MissingArgumentException
187187
* @expectedExceptionMessage parameters is missing
188188
*/
189189
public function testCreateReplyParamMissing()
@@ -209,7 +209,7 @@ public function testVote()
209209
}
210210

211211
/**
212-
* @expectedException Imgur\Exception\InvalidArgumentException
212+
* @expectedException \Imgur\Exception\InvalidArgumentException
213213
* @expectedExceptionMessage is wrong. Possible values are
214214
*/
215215
public function testVoteWrongVoteValue()

tests/Api/ConversationTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ protected function getApiClass()
1818
}
1919

2020
/**
21-
* @expectedException Imgur\Exception\ErrorException
21+
* @expectedException \Imgur\Exception\ErrorException
2222
* @expectedExceptionMessage Authentication required
2323
*/
2424
public function testBaseReal()
@@ -124,7 +124,7 @@ public function testMessageCreate()
124124
}
125125

126126
/**
127-
* @expectedException Imgur\Exception\MissingArgumentException
127+
* @expectedException \Imgur\Exception\MissingArgumentException
128128
* @expectedExceptionMessage parameters is missing
129129
*/
130130
public function testMessageCreateParamMissing()

tests/Api/CustomGalleryTest.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ protected function getApiClass()
1818
}
1919

2020
/**
21-
* @expectedException Imgur\Exception\ErrorException
21+
* @expectedException \Imgur\Exception\ErrorException
2222
* @expectedExceptionMessage Authentication required
2323
*/
2424
public function testBaseReal()
@@ -115,7 +115,7 @@ public function testCustomGallery()
115115
}
116116

117117
/**
118-
* @expectedException Imgur\Exception\InvalidArgumentException
118+
* @expectedException \Imgur\Exception\InvalidArgumentException
119119
* @expectedExceptionMessage is wrong. Possible values are
120120
*/
121121
public function testCustomGalleryWrongSortValue()
@@ -124,7 +124,7 @@ public function testCustomGalleryWrongSortValue()
124124
}
125125

126126
/**
127-
* @expectedException Imgur\Exception\InvalidArgumentException
127+
* @expectedException \Imgur\Exception\InvalidArgumentException
128128
* @expectedExceptionMessage is wrong. Possible values are
129129
*/
130130
public function testCustomGalleryWrongWindowValue()
@@ -152,7 +152,7 @@ public function testFiltered()
152152
}
153153

154154
/**
155-
* @expectedException Imgur\Exception\InvalidArgumentException
155+
* @expectedException \Imgur\Exception\InvalidArgumentException
156156
* @expectedExceptionMessage is wrong. Possible values are
157157
*/
158158
public function testFilteredWrongSortValue()
@@ -161,7 +161,7 @@ public function testFilteredWrongSortValue()
161161
}
162162

163163
/**
164-
* @expectedException Imgur\Exception\InvalidArgumentException
164+
* @expectedException \Imgur\Exception\InvalidArgumentException
165165
* @expectedExceptionMessage is wrong. Possible values are
166166
*/
167167
public function testFilteredWrongWindowValue()

tests/Api/GalleryTest.php

+17-17
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ protected function getApiClass()
1818
}
1919

2020
/**
21-
* @expectedException Imgur\Exception\ErrorException
21+
* @expectedException \Imgur\Exception\ErrorException
2222
* @expectedExceptionMessage Authentication required
2323
*/
2424
public function testBaseReal()
@@ -132,7 +132,7 @@ public function testGallery()
132132
}
133133

134134
/**
135-
* @expectedException Imgur\Exception\InvalidArgumentException
135+
* @expectedException \Imgur\Exception\InvalidArgumentException
136136
* @expectedExceptionMessage is wrong. Possible values are
137137
*/
138138
public function testGalleryWrongSortValue()
@@ -141,7 +141,7 @@ public function testGalleryWrongSortValue()
141141
}
142142

143143
/**
144-
* @expectedException Imgur\Exception\InvalidArgumentException
144+
* @expectedException \Imgur\Exception\InvalidArgumentException
145145
* @expectedExceptionMessage is wrong. Possible values are
146146
*/
147147
public function testGalleryWrongSectionValue()
@@ -150,7 +150,7 @@ public function testGalleryWrongSectionValue()
150150
}
151151

152152
/**
153-
* @expectedException Imgur\Exception\InvalidArgumentException
153+
* @expectedException \Imgur\Exception\InvalidArgumentException
154154
* @expectedExceptionMessage is wrong. Possible values are
155155
*/
156156
public function testGalleryWrongWindowValue()
@@ -180,7 +180,7 @@ public function testMemesSubgallery()
180180
}
181181

182182
/**
183-
* @expectedException Imgur\Exception\InvalidArgumentException
183+
* @expectedException \Imgur\Exception\InvalidArgumentException
184184
* @expectedExceptionMessage is wrong. Possible values are
185185
*/
186186
public function testMemesSubgalleryWrongSortValue()
@@ -189,7 +189,7 @@ public function testMemesSubgalleryWrongSortValue()
189189
}
190190

191191
/**
192-
* @expectedException Imgur\Exception\InvalidArgumentException
192+
* @expectedException \Imgur\Exception\InvalidArgumentException
193193
* @expectedExceptionMessage is wrong. Possible values are
194194
*/
195195
public function testMemesSubgalleryWrongWindowValue()
@@ -238,7 +238,7 @@ public function testSubredditGalleries()
238238
}
239239

240240
/**
241-
* @expectedException Imgur\Exception\InvalidArgumentException
241+
* @expectedException \Imgur\Exception\InvalidArgumentException
242242
* @expectedExceptionMessage is wrong. Possible values are
243243
*/
244244
public function testSubredditGalleriesWrongSortValue()
@@ -247,7 +247,7 @@ public function testSubredditGalleriesWrongSortValue()
247247
}
248248

249249
/**
250-
* @expectedException Imgur\Exception\InvalidArgumentException
250+
* @expectedException \Imgur\Exception\InvalidArgumentException
251251
* @expectedExceptionMessage is wrong. Possible values are
252252
*/
253253
public function testSubredditGalleriesWrongWindowValue()
@@ -296,7 +296,7 @@ public function testGalleryTag()
296296
}
297297

298298
/**
299-
* @expectedException Imgur\Exception\InvalidArgumentException
299+
* @expectedException \Imgur\Exception\InvalidArgumentException
300300
* @expectedExceptionMessage is wrong. Possible values are
301301
*/
302302
public function testGalleryTagWrongSortValue()
@@ -305,7 +305,7 @@ public function testGalleryTagWrongSortValue()
305305
}
306306

307307
/**
308-
* @expectedException Imgur\Exception\InvalidArgumentException
308+
* @expectedException \Imgur\Exception\InvalidArgumentException
309309
* @expectedExceptionMessage is wrong. Possible values are
310310
*/
311311
public function testGalleryTagWrongWindowValue()
@@ -369,7 +369,7 @@ public function testGalleryVoteTag()
369369
}
370370

371371
/**
372-
* @expectedException Imgur\Exception\InvalidArgumentException
372+
* @expectedException \Imgur\Exception\InvalidArgumentException
373373
* @expectedExceptionMessage is wrong. Possible values are
374374
*/
375375
public function testGalleryVoteTagWrongVoteValue()
@@ -399,7 +399,7 @@ public function testSearch()
399399
}
400400

401401
/**
402-
* @expectedException Imgur\Exception\InvalidArgumentException
402+
* @expectedException \Imgur\Exception\InvalidArgumentException
403403
* @expectedExceptionMessage is wrong. Possible values are
404404
*/
405405
public function testSearchWrongValues()
@@ -446,7 +446,7 @@ public function testSubmitToGallery()
446446
}
447447

448448
/**
449-
* @expectedException Imgur\Exception\MissingArgumentException
449+
* @expectedException \Imgur\Exception\MissingArgumentException
450450
* @expectedExceptionMessage parameters is missing
451451
*/
452452
public function testSubmitToGalleryParamMissing()
@@ -563,7 +563,7 @@ public function testVote()
563563
}
564564

565565
/**
566-
* @expectedException Imgur\Exception\InvalidArgumentException
566+
* @expectedException \Imgur\Exception\InvalidArgumentException
567567
* @expectedExceptionMessage is wrong. Possible values are
568568
*/
569569
public function testVoteWrongVoteValue()
@@ -593,7 +593,7 @@ public function testComments()
593593
}
594594

595595
/**
596-
* @expectedException Imgur\Exception\InvalidArgumentException
596+
* @expectedException \Imgur\Exception\InvalidArgumentException
597597
* @expectedExceptionMessage is wrong. Possible values are
598598
*/
599599
public function testCommentsWrongValues()
@@ -638,7 +638,7 @@ public function testCreateComment()
638638
}
639639

640640
/**
641-
* @expectedException Imgur\Exception\MissingArgumentException
641+
* @expectedException \Imgur\Exception\MissingArgumentException
642642
* @expectedExceptionMessage parameters is missing
643643
*/
644644
public function testCreateCommentParamMissing()
@@ -664,7 +664,7 @@ public function testCreateReply()
664664
}
665665

666666
/**
667-
* @expectedException Imgur\Exception\MissingArgumentException
667+
* @expectedException \Imgur\Exception\MissingArgumentException
668668
* @expectedExceptionMessage parameters is missing
669669
*/
670670
public function testCreateReplyParamMissing()

tests/Api/ImageTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ protected function getApiClass()
1818
}
1919

2020
/**
21-
* @expectedException Imgur\Exception\ErrorException
21+
* @expectedException \Imgur\Exception\ErrorException
2222
* @expectedExceptionMessage Authentication required
2323
*/
2424
public function testBaseReal()
@@ -150,7 +150,7 @@ public function testUploadWithFile()
150150
}
151151

152152
/**
153-
* @expectedException Imgur\Exception\InvalidArgumentException
153+
* @expectedException \Imgur\Exception\InvalidArgumentException
154154
* @expectedExceptionMessage is wrong. Possible values are
155155
*/
156156
public function testUploadWithBadType()
@@ -159,7 +159,7 @@ public function testUploadWithBadType()
159159
}
160160

161161
/**
162-
* @expectedException Imgur\Exception\MissingArgumentException
162+
* @expectedException \Imgur\Exception\MissingArgumentException
163163
* @expectedExceptionMessage parameters is missing
164164
*/
165165
public function testUploadWithUrlParamMissing()

0 commit comments

Comments
 (0)