Cheetah
FacebookResponseException.php
Go to the documentation of this file.
1 <?php
24 namespace Facebook\Exceptions;
25 
27 
34 {
38  protected $response;
39 
43  protected $responseData;
44 
51  public function __construct(FacebookResponse $response, FacebookSDKException $previousException = null)
52  {
53  $this->response = $response;
54  $this->responseData = $response->getDecodedBody();
55 
56  $errorMessage = $this->get('message', 'Unknown error from Graph.');
57  $errorCode = $this->get('code', -1);
58 
59  parent::__construct($errorMessage, $errorCode, $previousException);
60  }
61 
69  public static function create(FacebookResponse $response)
70  {
71  $data = $response->getDecodedBody();
72 
73  if (!isset($data['error']['code']) && isset($data['code'])) {
74  $data = ['error' => $data];
75  }
76 
77  $code = isset($data['error']['code']) ? $data['error']['code'] : null;
78  $message = isset($data['error']['message']) ? $data['error']['message'] : 'Unknown error from Graph.';
79 
80  if (isset($data['error']['error_subcode'])) {
81  switch ($data['error']['error_subcode']) {
82  // Other authentication issues
83  case 458:
84  case 459:
85  case 460:
86  case 463:
87  case 464:
88  case 467:
89  return new static($response, new FacebookAuthenticationException($message, $code));
90  // Video upload resumable error
91  case 1363030:
92  case 1363019:
93  case 1363037:
94  case 1363033:
95  case 1363021:
96  case 1363041:
97  return new static($response, new FacebookResumableUploadException($message, $code));
98  }
99  }
100 
101  switch ($code) {
102  // Login status or token expired, revoked, or invalid
103  case 100:
104  case 102:
105  case 190:
106  return new static($response, new FacebookAuthenticationException($message, $code));
107 
108  // Server issue, possible downtime
109  case 1:
110  case 2:
111  return new static($response, new FacebookServerException($message, $code));
112 
113  // API Throttling
114  case 4:
115  case 17:
116  case 32:
117  case 341:
118  case 613:
119  return new static($response, new FacebookThrottleException($message, $code));
120 
121  // Duplicate Post
122  case 506:
123  return new static($response, new FacebookClientException($message, $code));
124  }
125 
126  // Missing Permissions
127  if ($code == 10 || ($code >= 200 && $code <= 299)) {
128  return new static($response, new FacebookAuthorizationException($message, $code));
129  }
130 
131  // OAuth authentication error
132  if (isset($data['error']['type']) && $data['error']['type'] === 'OAuthException') {
133  return new static($response, new FacebookAuthenticationException($message, $code));
134  }
135 
136  // All others
137  return new static($response, new FacebookOtherException($message, $code));
138  }
139 
148  private function get($key, $default = null)
149  {
150  if (isset($this->responseData['error'][$key])) {
151  return $this->responseData['error'][$key];
152  }
153 
154  return $default;
155  }
156 
162  public function getHttpStatusCode()
163  {
164  return $this->response->getHttpStatusCode();
165  }
166 
172  public function getSubErrorCode()
173  {
174  return $this->get('error_subcode', -1);
175  }
176 
182  public function getErrorType()
183  {
184  return $this->get('type', '');
185  }
186 
192  public function getRawResponse()
193  {
194  return $this->response->getBody();
195  }
196 
202  public function getResponseData()
203  {
204  return $this->responseData;
205  }
206 
212  public function getResponse()
213  {
214  return $this->response;
215  }
216 }
Facebook\Exceptions\FacebookResponseException\getResponse
getResponse()
Definition: FacebookResponseException.php:212
Facebook\Exceptions\FacebookAuthenticationException
Definition: FacebookAuthenticationException.php:32
Facebook\Exceptions\FacebookSDKException
Definition: FacebookSDKException.php:32
Facebook\Exceptions\FacebookResponseException\getHttpStatusCode
getHttpStatusCode()
Definition: FacebookResponseException.php:162
Facebook\Exceptions\FacebookResponseException\$response
$response
Definition: FacebookResponseException.php:38
Facebook\Exceptions\FacebookResponseException\getSubErrorCode
getSubErrorCode()
Definition: FacebookResponseException.php:172
use
GNU LESSER GENERAL PUBLIC LICENSE February Free Software Inc Franklin Fifth MA USA Everyone is permitted to copy and distribute verbatim copies of this license but changing it is not allowed[This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it By the GNU General Public Licenses are intended to guarantee your freedom to share and change free software to make sure the software is free for all its users This the Lesser General Public applies to some specially designated software packages typically libraries of the Free Software Foundation and other authors who decide to use it You can use it but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular based on the explanations below When we speak of free we are referring to freedom of use
Definition: license.txt:27
Facebook\Exceptions\FacebookServerException
Definition: FacebookServerException.php:32
php
Facebook\FacebookResponse
Definition: FacebookResponse.php:36
Facebook\Exceptions\FacebookThrottleException
Definition: FacebookThrottleException.php:32
Facebook\Exceptions\FacebookResponseException\$responseData
$responseData
Definition: FacebookResponseException.php:43
Facebook\Exceptions\FacebookResumableUploadException
Definition: FacebookResumableUploadException.php:32
Facebook\Exceptions\FacebookResponseException
Definition: FacebookResponseException.php:34
Facebook\Exceptions
Definition: FacebookAuthenticationException.php:24
Facebook\Exceptions\FacebookClientException
Definition: FacebookClientException.php:32
Facebook\Exceptions\FacebookAuthorizationException
Definition: FacebookAuthorizationException.php:32
Facebook\Exceptions\FacebookOtherException
Definition: FacebookOtherException.php:32
Facebook\Exceptions\FacebookResponseException\getResponseData
getResponseData()
Definition: FacebookResponseException.php:202
Facebook\Exceptions\FacebookResponseException\__construct
__construct(FacebookResponse $response, FacebookSDKException $previousException=null)
Definition: FacebookResponseException.php:51
Facebook\Exceptions\FacebookResponseException\getRawResponse
getRawResponse()
Definition: FacebookResponseException.php:192
Facebook\Exceptions\FacebookResponseException\create
static create(FacebookResponse $response)
Definition: FacebookResponseException.php:69
Facebook\Exceptions\FacebookResponseException\getErrorType
getErrorType()
Definition: FacebookResponseException.php:182