Zend_Gdata_Exception.xml 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.gdata.exception">
  4. <title>Catching Gdata Exceptions</title>
  5. <para>
  6. The <classname>Zend_Gdata_App_Exception</classname> class is a base class
  7. for exceptions thrown by <classname>Zend_Gdata</classname>. You can catch any exception
  8. thrown by <classname>Zend_Gdata</classname> by catching <classname>Zend_Gdata_App_Exception</classname>.
  9. </para>
  10. <programlisting language="php"><![CDATA[
  11. try {
  12. $client =
  13. Zend_Gdata_ClientLogin::getHttpClient($username, $password);
  14. } catch(Zend_Gdata_App_Exception $ex) {
  15. // Report the exception to the user
  16. die($ex->getMessage());
  17. }
  18. ]]></programlisting>
  19. <para>
  20. The following exception subclasses are used by <classname>Zend_Gdata</classname>:
  21. <itemizedlist>
  22. <listitem>
  23. <para>
  24. <classname>Zend_Gdata_App_AuthException</classname>
  25. indicates that the user's account credentials were not valid.
  26. </para>
  27. </listitem>
  28. <listitem>
  29. <para>
  30. <classname>Zend_Gdata_App_BadMethodCallException</classname>
  31. indicates that a method was called for a service
  32. that does not support the method. For example,
  33. the CodeSearch service does not support <code>post()</code>.
  34. </para>
  35. </listitem>
  36. <listitem>
  37. <para>
  38. <classname>Zend_Gdata_App_HttpException</classname>
  39. indicates that an HTTP request was not successful.
  40. Provides the ability to get the full <classname>Zend_Http_Response</classname>
  41. object to determine the exact cause of the failure in
  42. cases where <code>$e->getMessage()</code> does not provide
  43. enough details.
  44. </para>
  45. </listitem>
  46. <listitem>
  47. <para>
  48. <classname>Zend_Gdata_App_InvalidArgumentException</classname>
  49. is thrown when the application provides a value that
  50. is not valid in a given context. For example,
  51. specifying a Calendar visibility value of "banana",
  52. or fetching a Blogger feed without specifying
  53. any blog name.
  54. </para>
  55. </listitem>
  56. <listitem>
  57. <para>
  58. <classname>Zend_Gdata_App_CaptchaRequiredException</classname>
  59. is thrown when a ClientLogin attempt receives a
  60. <trademark>CAPTCHA</trademark> challenge from the
  61. authentication service. This exception contains a token
  62. ID and a URL to a <trademark>CAPTCHA</trademark>
  63. challenge image. The image is a visual puzzle that
  64. should be displayed to the user. After
  65. collecting the user's response to the challenge
  66. image, the response can be included with the next
  67. ClientLogin attempt.The user can alternatively be
  68. directed to this website:
  69. <ulink url="https://www.google.com/accounts/DisplayUnlockCaptcha"/>
  70. Further information can be found in the
  71. <link linkend="zend.gdata.clientlogin">ClientLogin documentation</link>.
  72. </para>
  73. </listitem>
  74. </itemizedlist>
  75. </para>
  76. <para>
  77. You can use these exception subclasses to handle specific exceptions
  78. differently. See the API documentation for information on which
  79. exception subclasses are thrown by which methods in <classname>Zend_Gdata</classname>.
  80. </para>
  81. <programlisting language="php"><![CDATA[
  82. try {
  83. $client = Zend_Gdata_ClientLogin::getHttpClient($username,
  84. $password,
  85. $service);
  86. } catch(Zend_Gdata_App_AuthException $authEx) {
  87. // The user's credentials were incorrect.
  88. // It would be appropriate to give the user a second try.
  89. ...
  90. } catch(Zend_Gdata_App_HttpException $httpEx) {
  91. // Google Data servers cannot be contacted.
  92. die($httpEx->getMessage);}
  93. ]]></programlisting>
  94. </sect1>