ErrorResult.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * ErrorResult
  4. * The error result class.
  5. *
  6. * @package Elgg.Core
  7. * @subpackage WebServicesAPI
  8. */
  9. class ErrorResult extends GenericResult {
  10. // Fail with no specific code
  11. public static $RESULT_FAIL = -1 ;
  12. public static $RESULT_FAIL_APIKEY_DISABLED = -30;
  13. public static $RESULT_FAIL_APIKEY_INACTIVE = -31;
  14. public static $RESULT_FAIL_APIKEY_INVALID = -32;
  15. // Invalid, expired or missing auth token
  16. public static $RESULT_FAIL_AUTHTOKEN = -20;
  17. /**
  18. * A new error result
  19. *
  20. * @param string $message Message
  21. * @param int $code Error Code
  22. * @param Exception $exception Exception object
  23. *
  24. * @return void
  25. */
  26. public function __construct($message, $code = "", Exception $exception = NULL) {
  27. if ($code == "") {
  28. $code = ErrorResult::$RESULT_FAIL;
  29. }
  30. if ($exception != NULL) {
  31. $this->setResult($exception->__toString());
  32. }
  33. $this->setStatusCode($code, $message);
  34. }
  35. /**
  36. * Get a new instance of the ErrorResult.
  37. *
  38. * @param string $message Message
  39. * @param int $code Code
  40. * @param Exception $exception Optional exception for generating a stack trace.
  41. *
  42. * @return ErrorResult
  43. */
  44. public static function getInstance($message, $code = "", Exception $exception = NULL) {
  45. // Return a new error object.
  46. return new ErrorResult($message, $code, $exception);
  47. }
  48. }