File tree Expand file tree Collapse file tree 5 files changed +55
-6
lines changed
lib/OpenCloud/ObjectStore
tests/OpenCloud/Tests/ObjectStore/Resource Expand file tree Collapse file tree 5 files changed +55
-6
lines changed Original file line number Diff line number Diff line change @@ -45,5 +45,4 @@ public function getAccount()
45
45
{
46
46
return new Resource \Account ($ this );
47
47
}
48
-
49
48
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace OpenCloud \ObjectStore \Exception ;
4
+
5
+ class ObjectNotFoundException extends \RuntimeException
6
+ {
7
+ public static function factory ($ name , \Exception $ exception )
8
+ {
9
+ $ message = sprintf (
10
+ "%s could not be found. The API returned this HTTP response: \n\n%s " ,
11
+ $ name ,
12
+ (string ) $ exception ->getResponse ()
13
+ );
14
+
15
+ $ e = new self ($ message );
16
+
17
+ $ e ->name = $ name ;
18
+ $ e ->response = $ exception ->getResponse ();
19
+ $ e ->request = $ exception ->getRequest ();
20
+
21
+ return $ e ;
22
+ }
23
+ }
Original file line number Diff line number Diff line change 11
11
namespace OpenCloud \ObjectStore \Resource ;
12
12
13
13
use Guzzle \Http \EntityBody ;
14
+ use Guzzle \Http \Exception \BadResponseException ;
14
15
use Guzzle \Http \Exception \ClientErrorResponseException ;
15
16
use Guzzle \Http \Message \Response ;
16
17
use Guzzle \Http \Url ;
19
20
use OpenCloud \Common \Service \ServiceInterface ;
20
21
use OpenCloud \ObjectStore \Constants \Header as HeaderConst ;
21
22
use OpenCloud \ObjectStore \Exception \ContainerException ;
23
+ use OpenCloud \ObjectStore \Exception \ObjectNotFoundException ;
22
24
use OpenCloud \ObjectStore \Upload \DirectorySync ;
23
25
use OpenCloud \ObjectStore \Upload \TransferBuilder ;
24
26
@@ -322,9 +324,16 @@ public function dataObject($info = null)
322
324
*/
323
325
public function getObject ($ name , array $ headers = array ())
324
326
{
325
- $ response = $ this ->getClient ()
326
- ->get ($ this ->getUrl ($ name ), $ headers )
327
- ->send ();
327
+ try {
328
+ $ response = $ this ->getClient ()
329
+ ->get ($ this ->getUrl ($ name ), $ headers )
330
+ ->send ();
331
+ } catch (BadResponseException $ e ) {
332
+ if ($ e ->getResponse ()->getStatusCode () == 404 ) {
333
+ throw ObjectNotFoundException::factory ($ name , $ e );
334
+ }
335
+ throw $ e ;
336
+ }
328
337
329
338
return $ this ->dataObject ()
330
339
->populateFromResponse ($ response )
Original file line number Diff line number Diff line change 10
10
11
11
namespace OpenCloud \Tests \ObjectStore \Resource ;
12
12
13
+ use Guzzle \Http \Message \Response ;
13
14
use OpenCloud \Common \Constants \Size ;
14
15
use OpenCloud \Tests \ObjectStore \ObjectStoreTestCase ;
15
16
@@ -148,7 +149,25 @@ public function test_Get_Object()
148
149
);
149
150
$ this ->assertEquals ('foobar ' , $ object ->getName ());
150
151
}
151
-
152
+
153
+ /**
154
+ * @expectedException \OpenCloud\ObjectStore\Exception\ObjectNotFoundException
155
+ */
156
+ public function test_Get_Object_404 ()
157
+ {
158
+ $ this ->addMockSubscriber (new Response (404 ));
159
+ $ this ->container ->getObject ('foobar ' );
160
+ }
161
+
162
+ /**
163
+ * @expectedException \Guzzle\Http\Exception\BadResponseException
164
+ */
165
+ public function test_Get_Object_500 ()
166
+ {
167
+ $ this ->addMockSubscriber (new Response (500 ));
168
+ $ this ->container ->getObject ('foobar ' );
169
+ }
170
+
152
171
/**
153
172
* @expectedException OpenCloud\Common\Exceptions\InvalidArgumentError
154
173
*/
Original file line number Diff line number Diff line change @@ -94,5 +94,4 @@ public function test_Public_Urls()
94
94
$ this ->assertNotNull ($ object ->getPublicUrl (UrlType::STREAMING ));
95
95
$ this ->assertNotNull ($ object ->getPublicUrl (UrlType::IOS_STREAMING ));
96
96
}
97
-
98
97
}
You can’t perform that action at this time.
0 commit comments