TencentCloudSDKException.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /*
  3. * Copyright (c) 2017-2018 THL A29 Limited, a Tencent company. All Rights Reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing,
  12. * software distributed under the License is distributed on an
  13. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. * KIND, either express or implied. See the License for the
  15. * specific language governing permissions and limitations
  16. * under the License.
  17. */
  18. namespace TencentCloud\Common\Exception;
  19. /**
  20. * sdk异常类
  21. * @package TencentCloud\Common\Exception
  22. */
  23. class TencentCloudSDKException extends \Exception
  24. {
  25. /**
  26. * @var string 请求id
  27. */
  28. private $requestId;
  29. private $errorCode;
  30. /**
  31. * TencentCloudSDKException constructor.
  32. * @param string $code 异常错误码
  33. * @param string $message 异常信息
  34. * @param string $requestId 请求ID
  35. */
  36. public function __construct($code = "", $message = "", $requestId = "")
  37. {
  38. parent::__construct($message, 0);
  39. $this->errorCode = $code;
  40. $this->requestId = $requestId;
  41. }
  42. /**
  43. * 返回请求id
  44. * @return string
  45. */
  46. public function getRequestId()
  47. {
  48. return $this->requestId;
  49. }
  50. /**
  51. * 返回错误码
  52. * @return string
  53. */
  54. public function getErrorCode()
  55. {
  56. return $this->errorCode;
  57. }
  58. /**
  59. * 格式化输出异常码,异常信息,请求id
  60. * @return string
  61. */
  62. public function __toString()
  63. {
  64. return "[".__CLASS__."]"." code:".$this->errorCode.
  65. " message:".$this->getMessage().
  66. " requestId:".$this->requestId;
  67. }
  68. }