From f2f370ba0ea154ba068275058b3b10f5a9c4b59f Mon Sep 17 00:00:00 2001 From: Richard Marmorstein Date: Mon, 28 Aug 2023 11:24:56 -0700 Subject: [PATCH 1/2] Nicer ApiErrorException::__toString() --- lib/Exception/ApiErrorException.php | 3 ++- tests/Stripe/Exception/ApiErrorExceptionTest.php | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/Exception/ApiErrorException.php b/lib/Exception/ApiErrorException.php index 995a42e69..e7b4feb74 100644 --- a/lib/Exception/ApiErrorException.php +++ b/lib/Exception/ApiErrorException.php @@ -202,10 +202,11 @@ public function setStripeCode($stripeCode) */ public function __toString() { + $parentStr = parent::__toString(); $statusStr = (null === $this->getHttpStatus()) ? '' : "(Status {$this->getHttpStatus()}) "; $idStr = (null === $this->getRequestId()) ? '' : "(Request {$this->getRequestId()}) "; - return "{$statusStr}{$idStr}{$this->getMessage()}"; + return "Error sending request to Stripe: {$statusStr}{$idStr}{$this->getMessage()}\n$parentStr"; } protected function constructErrorObject() diff --git a/tests/Stripe/Exception/ApiErrorExceptionTest.php b/tests/Stripe/Exception/ApiErrorExceptionTest.php index 29b1a4fd1..6ee5d1149 100644 --- a/tests/Stripe/Exception/ApiErrorExceptionTest.php +++ b/tests/Stripe/Exception/ApiErrorExceptionTest.php @@ -44,5 +44,7 @@ public function testToString() { $e = $this->createFixture(); static::compatAssertStringContainsString('(Request req_test)', (string) $e); + static::compatAssertStringContainsString('Error sending request to Stripe', (string) $e); + static::compatAssertStringContainsString('Stack trace:', (string) $e); } } From fa45a7064b38a8579782590a2ba3fffe97d5c0c3 Mon Sep 17 00:00:00 2001 From: Richard Marmorstein Date: Mon, 28 Aug 2023 11:33:00 -0700 Subject: [PATCH 2/2] Format --- lib/Exception/ApiErrorException.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Exception/ApiErrorException.php b/lib/Exception/ApiErrorException.php index e7b4feb74..f753d62c6 100644 --- a/lib/Exception/ApiErrorException.php +++ b/lib/Exception/ApiErrorException.php @@ -206,7 +206,7 @@ public function __toString() $statusStr = (null === $this->getHttpStatus()) ? '' : "(Status {$this->getHttpStatus()}) "; $idStr = (null === $this->getRequestId()) ? '' : "(Request {$this->getRequestId()}) "; - return "Error sending request to Stripe: {$statusStr}{$idStr}{$this->getMessage()}\n$parentStr"; + return "Error sending request to Stripe: {$statusStr}{$idStr}{$this->getMessage()}\n{$parentStr}"; } protected function constructErrorObject()