FacebookApiException

Thrown when an API call returns an exception.

Defined (1)

The class is defined in the following location(s).

/facebook/base_facebook.php  
  1. class FacebookApiException extends Exception 
  2. /** 
  3. * The result from the API server that represents the exception information. 
  4. */ 
  5. protected $result; 
  6.  
  7. /** 
  8. * Make a new API Exception with the given result. 
  9. * @param array $result The result from the API server 
  10. */ 
  11. public function __construct($result) { 
  12. $this->result = $result; 
  13.  
  14. $code = isset($result['error_code']) ? $result['error_code'] : 0; 
  15.  
  16. if (isset($result['error_description'])) { 
  17. // OAuth 2.0 Draft 10 style 
  18. $msg = $result['error_description']; 
  19. } else if (isset($result['error']) && is_array($result['error'])) { 
  20. // OAuth 2.0 Draft 00 style 
  21. $msg = $result['error']['message']; 
  22. } else if (isset($result['error_msg'])) { 
  23. // Rest server style 
  24. $msg = $result['error_msg']; 
  25. } else { 
  26. $msg = 'Unknown Error. Check getResult()'; 
  27.  
  28. parent::__construct($msg, $code); 
  29.  
  30. /** 
  31. * Return the associated result object returned by the API server. 
  32. * @return array The result from the API server 
  33. */ 
  34. public function getResult() { 
  35. return $this->result; 
  36.  
  37. /** 
  38. * Returns the associated type for the error. This will default to 
  39. * 'Exception' when a type is not available. 
  40. * @return string 
  41. */ 
  42. public function getType() { 
  43. if (isset($this->result['error'])) { 
  44. $error = $this->result['error']; 
  45. if (is_string($error)) { 
  46. // OAuth 2.0 Draft 10 style 
  47. return $error; 
  48. } else if (is_array($error)) { 
  49. // OAuth 2.0 Draft 00 style 
  50. if (isset($error['type'])) { 
  51. return $error['type']; 
  52.  
  53. return 'Exception'; 
  54.  
  55. /** 
  56. * To make debugging easier. 
  57. * @return string The string representation of the error 
  58. */ 
  59. public function __toString() { 
  60. $str = $this->getType() . ': '; 
  61. if ($this->code != 0) { 
  62. $str .= $this->code . ': '; 
  63. return $str . $this->message;