Zend_Gdata_Exception.xml 4.4 KB

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