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

delete() throwing exception on 404 instead of returning false #11

Closed
jjriv opened this issue Aug 25, 2013 · 7 comments
Closed

delete() throwing exception on 404 instead of returning false #11

jjriv opened this issue Aug 25, 2013 · 7 comments

Comments

@jjriv
Copy link

jjriv commented Aug 25, 2013

I'm making the following call:
$res = $os->with('container/filename.txt')->delete();

But instead of $res getting set to a boolean value, an exception is being thrown, which is not being caught, so a fatal error occurs:

Error level: 1
Error message: Uncaught exception 'ObjectStorage_Exception_Http_NotFound' with message 'Not Found' in /var/www/vhosts/jjriv.assignthis.com/app/LocalLib/ObjectStorage/ObjectStorage.php:531
Stack trace:
#0 /var/www/vhosts/jjriv.assignthis.com/app/LocalLib/ObjectStorage/ObjectStorage/Exception/Http.php(10): ObjectStorage_Exception_Http->throwException(404, NULL, '/var/www/vhosts...', 531)
#1 /var/www/vhosts/jjriv.assignthis.com/app/LocalLib/ObjectStorage/ObjectStorage.php(531): ObjectStorage_Exception_Http->__construct(NULL, 404)
#2 /var/www/vhosts/jjriv.assignthis.com/app/LocalLib/ObjectStorage/ObjectStorage/Abstract.php(607): ObjectStorage->delete(Object(ObjectStorage_Object))
#3 /var/www/vhosts/jjriv.assignthis.com/app/cron/upload_garbage_collection.php(56): ObjectStorage_Abstract->delete()

But in the unit test docs, the delete() is not performed inside a try/catch clause:
https://github.com/softlayer/softlayer-object-storage-php/blob/master/tests/ObjectTest.php

And according to the Openstack documentation, 404 is a valid response for when the object does not exist:
http://docs.openstack.org/api/openstack-object-storage/1.0/content/delete-object.html

Do I need to put my delete() code inside a try/catch or is this a bug? Thanks!

@its-clee
Copy link
Contributor

Hello,

As you pointed out 404 response is expected when a DELETE request is performed on an object that doesn't exist. I'd suggest you wrap the delete call with a try/catch block.

The unit test expects the delete operation to be successful. I wanted the test to fail if the delete operation is not successful. Sorry about the confusion though.

Cheers!

@jjriv
Copy link
Author

jjriv commented Aug 26, 2013

Thanks for getting back to me and for the confirmation. I went ahead and wrapped the delete call, along with all other calls to ObjectStorage, inside a try/catch block. This way it won't cause a fatal error within my web application. One last question. Once I've caught the 404, or whatever the exception might be, is there a way to get the status code that was received? Something like $e->getStatusCode() where $e is an Exception object?

@its-clee
Copy link
Contributor

I think the ability to get the HTTP code from an exception is a great idea. I will implement the exception code for all HTTP exception sub classes so you can use $e->getCode(). Also, I will update all ObjectStorage_Exception_Http_* classes to implement ObjectStorage_Exception_Http_Interface so you can expect the HTTP status code when you're catching these exceptions.

@jjriv
Copy link
Author

jjriv commented Aug 26, 2013

Wow! That would be very helpful. Thanks! I'll look forward to the update.

@its-clee
Copy link
Contributor

HTTP exceptions will have the status code now.

Cheers!

@CrackerJackMack
Copy link
Contributor

Probably needs docs in the README

@briancline
Copy link
Member

Going ahead and closing this since it looks like it was resolved with c65981b. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants