Skip to content

Commit

Permalink
Merge pull request #1562 from stripe/richardm-nicer-exception-tostring
Browse files Browse the repository at this point in the history
Nicer ApiErrorException::__toString()
  • Loading branch information
richardm-stripe authored Aug 29, 2023
2 parents d7af9fc + a947b5e commit 18d6862
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/Exception/ApiErrorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions tests/Stripe/Exception/ApiErrorExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 18d6862

Please sign in to comment.