HenryC Posted June 3, 2011 Share Posted June 3, 2011 Hello everyone i'm new here, my name is Henry and great forums you have here.. Now to my question I am creating a small sub 4 sub website for our little community of people but may expand in the future and im using the youtube api, like other sub 4 sub sites we have a page where we display all the users to be subbed to, now my problem is if a user is already subscribed to another user before they come on to my site then they will still show up in the sub4sub page and when clicking to subscribe to them gets a exception error Fatal error: Uncaught exception 'Zend_Gdata_App_HttpException' with message 'Expected response code 200, got 400 Subscription already exists.' in /home/u292976682/public_html/Zend/library/Zend/Gdata/App.php:709 Stack trace: #0 /home/u292976682/public_html/Zend/library/Zend/Gdata.php(219): Zend_Gdata_App->performHttpRequest('POST', 'http://gdata.yo...', Array, '<atom:entry xml...', 'application/ato...', NULL) #1 /home/u292976682/public_html/Zend/library/Zend/Gdata/App.php(900): Zend_Gdata->performHttpRequest('POST', 'http://gdata.yo...', Array, '<atom:entry xml...', 'application/ato...') #2 /home/u292976682/public_html/Zend/library/Zend/Gdata/App.php(975): Zend_Gdata_App->post(Object(Zend_Gdata_YouTube_SubscriptionEntry), 'http://gdata.yo...', NULL, NULL, Array) #3 /home/u292976682/public_html/sub4sub.php(55): I dont think there is a way to stop it because they were subscribed from somewhere other than my site, is there a way to hide the error or so? I would be thankfull for any help in this thank you. Quote Link to comment https://forums.phpfreaks.com/topic/238300-little-help-with-exception/ Share on other sites More sharing options...
Adam Posted June 3, 2011 Share Posted June 3, 2011 You need to use a try...catch block to catch the exception, otherwise you'll get the "uncaught exception" fatal error you are doing. try { // code triggering the exception here } catch (Zend_Gdata_App_HttpException $e) { // handle the error here } Note that the code after the catch block will still be executed, so think about that in your handling code. If you want you could specify the generic "Exception $e" instead, which will catch all descendant types of Exception as one. Or you can specify multiple catch blocks to handle certain exceptions differently: try { // code triggering the exception here } catch (Zend_Gdata_App_HttpException $e) { // handle this specific exception here } catch (Exception $e) { // catch all other types of Exception here } I'd strongly recommend reading up on them before hand, as people tend to find them quite confusing at first. Quote Link to comment https://forums.phpfreaks.com/topic/238300-little-help-with-exception/#findComment-1224611 Share on other sites More sharing options...
HenryC Posted June 3, 2011 Author Share Posted June 3, 2011 Yes that worked great <?php try { $yt->insertEntry($newSubscription, $subscriptionsFeedUrl); //insert query with points } catch (Zend_Gdata_App_HttpException $e) { //insert query without points } So if there is an exception then the query still goes but without giving the user points for the sub because they are already subbed. no errors at all. Thanks alot MrAdam.. Quote Link to comment https://forums.phpfreaks.com/topic/238300-little-help-with-exception/#findComment-1224640 Share on other sites More sharing options...
Adam Posted June 3, 2011 Share Posted June 3, 2011 No worries. Though it's generally appropriate in the case of an exception to raise some kind of flag to the user (which can you can handle within the catch block) to notify them if something hasn't happened like they're expecting. That might not be the case this time though. Quote Link to comment https://forums.phpfreaks.com/topic/238300-little-help-with-exception/#findComment-1224684 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.