Base.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace Stripe\Error;
  3. use Exception;
  4. abstract class Base extends Exception
  5. {
  6. public function __construct(
  7. $message,
  8. $httpStatus = null,
  9. $httpBody = null,
  10. $jsonBody = null,
  11. $httpHeaders = null
  12. ) {
  13. parent::__construct($message);
  14. $this->httpStatus = $httpStatus;
  15. $this->httpBody = $httpBody;
  16. $this->jsonBody = $jsonBody;
  17. $this->httpHeaders = $httpHeaders;
  18. $this->requestId = null;
  19. if ($httpHeaders && isset($httpHeaders['Request-Id'])) {
  20. $this->requestId = $httpHeaders['Request-Id'];
  21. }
  22. }
  23. public function getHttpStatus()
  24. {
  25. return $this->httpStatus;
  26. }
  27. public function getHttpBody()
  28. {
  29. return $this->httpBody;
  30. }
  31. public function getJsonBody()
  32. {
  33. return $this->jsonBody;
  34. }
  35. public function getHttpHeaders()
  36. {
  37. return $this->httpHeaders;
  38. }
  39. public function getRequestId()
  40. {
  41. return $this->requestId;
  42. }
  43. public function __toString()
  44. {
  45. $id = $this->requestId ? " from API request '{$this->requestId}'": "";
  46. $message = explode("\n", parent::__toString());
  47. $message[0] .= $id;
  48. return implode("\n", $message);
  49. }
  50. }