functions.php 985 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /**
  3. * @ignore 公共函数库
  4. */
  5. namespace Easemob;
  6. /**
  7. * @ignore 返回错误信息
  8. * @param Response $response 响应对象
  9. * @param string $message 错误信息
  10. * @param int $code 错误码
  11. * @return array 返回信息
  12. */
  13. function error($response, $message = null, $code = 1)
  14. {
  15. if ($response !== null) {
  16. $data = $response->data();
  17. return array(
  18. 'code' => $response->httpCode,
  19. 'error' => isset($data['error']) ? $data['error'] : $response->error,
  20. 'error_description' => isset($data['error_description']) ? $data['error_description'] : '',
  21. );
  22. }
  23. return array(
  24. 'code' => $code,
  25. 'error' => $message,
  26. );
  27. // throw new \Exception($message, $code);
  28. }
  29. /**
  30. * @ignore 输出异常信息
  31. * @param string $message 异常信息
  32. * @param int $code 错误码
  33. */
  34. function exception($message, $code = 1)
  35. {
  36. throw new \Exception($message, $code);
  37. }