PageRenderTime 60ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/Varien/Gdata/Gshopping/HttpException.php

https://bitbucket.org/jokusafet/magento2
PHP | 166 lines | 129 code | 1 blank | 36 comment | 6 complexity | d61fe087b01f9df355cc7e0cf855f4b8 MD5 | raw file
  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magentocommerce.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magentocommerce.com for more information.
  20. *
  21. * @category Varien
  22. * @package Varien_Gdata
  23. * @copyright Copyright (c) 2012 X.commerce, Inc. (http://www.magentocommerce.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * Exception class parse google responses to human readble format
  28. *
  29. * @category Varien
  30. * @package Varien_Gdata
  31. */
  32. class Varien_Gdata_Gshopping_HttpException extends Zend_Gdata_App_HttpException
  33. {
  34. /**
  35. * Array of descriptions for Google's error codes.
  36. * array('code' => 'description')
  37. *
  38. * @var array
  39. */
  40. protected $_errors = array(
  41. 'auth/frontend/adwords' => "Your AdWords advertisements are not running. You need to activate your AdWords account.",
  42. 'auth/frontend/checkout' => "Google Checkout not enabled",
  43. 'auth/frontend/feed_config' => "You have not set your data feed to go live",
  44. 'auth/frontend/missing_homepage' => "You haven't specified your website's URL on the settings page before uploading items.",
  45. 'auth/frontend/not_claimed' => "You didn't verify and claim your website's URL.",
  46. 'auth/frontend/terms_of_service' => "You didn't sign the Merchant Center's terms of service.",
  47. 'quota/geo_mutation' => "Geo quota exceeded.",
  48. 'quota/geo_request' => "Geo quota exceeded.",
  49. 'quota/too_many_feeds' => "You have too many data feeds registered.",
  50. 'quota/too_many_requests' => "You executed too many requests.",
  51. 'quota/too_many_subaccounts' => "You have too many subaccounts registered.",
  52. 'validation/checkout_not_supported' => "Google Checkout not supported for this type of item.",
  53. 'validation/feed' => "Multiple reasons why a data feed upload failed.",
  54. 'validation/internal' => "Internal error during validation. Please retry inserting the item. If the problem persist, please report this issue to us together with the request you're trying to execute.",
  55. 'validation/invalid_attribute' => "Error code covering various reasons why the attribute is invalid.",
  56. 'validation/invalid_attribute/duplicate' => "The item contains two identical attributes (with identical values).",
  57. 'validation/invalid_attribute/reserved' => "The attribute you're trying to insert uses a name reserved by Content API for Shopping.",
  58. 'validation/invalid_attribute/too_many' => "The attribute has too many values.",
  59. 'validation/invalid_attribute/unknown' => "The attribute is not supported.",
  60. 'validation/invalid_character' => "There is a problem with the character encoding of this attribute.",
  61. 'validation/invalid_destination' => "Specified destination is not supported. See the Destinations section for more information.",
  62. 'validation/invalid_format' => "The format of the attribute value is not valid (e.g. dates, numbers).",
  63. 'validation/invalid_item' => "Generic error code for an invalid item. Check the content of the <internalReason> element for more information of the reason.",
  64. 'validation/invalid_value' => "Generic error code for an invalid value of an attribute.",
  65. 'validation/invalid_value/missing' => "You didn't specify a value for an attribute.",
  66. 'validation/invalid_value/too_high' => "The numeric value is too high.",
  67. 'validation/invalid_value/too_long' => "The text value is too long.",
  68. 'validation/invalid_value/too_low' => "The numeric value is too low.",
  69. 'validation/invalid_value/unknown' => "The value you specified for this attribute is not in the list of the supported values.",
  70. 'validation/missing_recommended' => "A recommended attribute is missing.",
  71. 'validation/missing_required' => "A required attribute is missing.",
  72. 'validation/other' => "Generic validation error.",
  73. 'validation/policy' => "One of the policies has been violated.",
  74. 'validation/warning' => "We found this attribute problematic for some reason and recommend checking it.",
  75. );
  76. /**
  77. * Error codes.
  78. * One exception may have several codes.
  79. *
  80. * @var array codes
  81. */
  82. protected $_codes = array();
  83. /**
  84. * Error messages.
  85. * One exception may have several codes with messages.
  86. *
  87. * @var array messages
  88. */
  89. protected $_messages = array();
  90. public function __construct($message = null, $httpClientException = null, $response = null)
  91. {
  92. if ($message instanceof Zend_Gdata_App_HttpException) {
  93. parent::__construct($message->getMessage(), $message->getHttpClientException(), $message->getResponse());
  94. } else {
  95. parent::__construct($message, $httpClientException, $response);
  96. }
  97. $this->_parseResponse($this->_response);
  98. }
  99. /**
  100. * Set the Zend_Http_Response.
  101. *
  102. * @param Zend_Http_Response $response
  103. */
  104. public function setResponse($response)
  105. {
  106. $this->_parseResponse($response);
  107. return parent::setResponse($response);
  108. }
  109. /**
  110. * Get array of error messages
  111. *
  112. * @return array
  113. */
  114. public function getMessages()
  115. {
  116. return $this->_messages;
  117. }
  118. /**
  119. * Get array of error codes
  120. *
  121. * @return array
  122. */
  123. public function getCodes()
  124. {
  125. return $this->_codes;
  126. }
  127. /**
  128. * Parse error response XML and fill arrays of codes and messages.
  129. *
  130. * @param Zend_Http_Response $response
  131. * @return Varien_Gdata_Gshopping_HttpException
  132. */
  133. protected function _parseResponse($response)
  134. {
  135. if (!$response instanceof Zend_Http_Response) {
  136. return;
  137. }
  138. $body = $response->getBody();
  139. if ($body &&
  140. ($errors = @simplexml_load_string($body)) &&
  141. 'errors' == $errors->getName()) {
  142. $this->_messages = array();
  143. $this->_codes = array();
  144. foreach ($errors as $error) {
  145. $reason = isset($this->_errors["$error->code"])
  146. ? $this->_errors["$error->code"]
  147. : "Error code: $error->code.";
  148. $this->_messages[] = "$reason Internal reason: $error->internalReason @ $error->location\n";
  149. $this->_codes[] = "$error->code";
  150. }
  151. $this->message = implode("\n", $this->_messages);
  152. $this->code = implode(';', $this->_codes);
  153. }
  154. return $this;
  155. }
  156. }