Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nicer ApiErrorException::__toString() #1562

Merged
merged 3 commits into from
Aug 29, 2023

Conversation

richardm-stripe
Copy link
Contributor

@richardm-stripe richardm-stripe commented Aug 28, 2023

Fixes #1561

Changes ApiErrorException::__toString() to have more useful information (a stack trace). This should be a safe change: __toString() is for human consumption and not intended to be consumed programatically.

Before this change:

(Status 200) (Request req_test) message

After this change:

Error sending request to Stripe: (Status 200) (Request req_test) message
Mock_ApiErrorException_21f57d2b: message in /Users/richardm/stripe/stripe-php/lib/Exception/ApiErrorException.php:38
Stack trace:
#0 /Users/richardm/stripe/stripe-php/tests/Stripe/Exception/ApiErrorExceptionTest.php(17): Stripe\Exception\ApiErrorException::factory('message', 200, '{"error": {"cod...', Array, Array, 'some_code')
#1 /Users/richardm/stripe/stripe-php/tests/Stripe/Exception/ApiErrorExceptionTest.php(45): Stripe\Exception\ApiErrorExceptionTest->createFixture()
#2 /Users/richardm/stripe/stripe-php/vendor/phpunit/phpunit/src/Framework/TestCase.php(1608): Stripe\Exception\ApiErrorExceptionTest->testToString()
#3 /Users/richardm/stripe/stripe-php/vendor/phpunit/phpunit/src/Framework/TestCase.php(1214): PHPUnit\Framework\TestCase->runTest()
#4 /Users/richardm/stripe/stripe-php/vendor/phpunit/phpunit/src/Framework/TestResult.php(728): PHPUnit\Framework\TestCase->runBare()
#5 /Users/richardm/stripe/stripe-php/vendor/phpunit/phpunit/src/Framework/TestCase.php(964): PHPUnit\Framework\TestResult->run(Object(Stripe\Exception\ApiErrorExceptionTest))
#6 /Users/richardm/stripe/stripe-php/vendor/phpunit/phpunit/src/Framework/TestSuite.php(684): PHPUnit\Framework\TestCase->run(Object(PHPUnit\Framework\TestResult))
#7 /Users/richardm/stripe/stripe-php/vendor/phpunit/phpunit/src/TextUI/TestRunner.php(653): PHPUnit\Framework\TestSuite->run(Object(PHPUnit\Framework\TestResult))
#8 /Users/richardm/stripe/stripe-php/vendor/phpunit/phpunit/src/TextUI/Command.php(144): PHPUnit\TextUI\TestRunner->run(Object(PHPUnit\Framework\TestSuite), Array, Array, true)
#9 /Users/richardm/stripe/stripe-php/vendor/phpunit/phpunit/src/TextUI/Command.php(97): PHPUnit\TextUI\Command->run(Array, true)
#10 /Users/richardm/stripe/stripe-php/vendor/phpunit/phpunit/phpunit(98): PHPUnit\TextUI\Command::main()
#11 /Users/richardm/stripe/stripe-php/vendor/bin/phpunit(123): include('/Users/richardm...')
#12 {main}

@richardm-stripe richardm-stripe requested review from a team and anniel-stripe and removed request for a team August 28, 2023 18:32
@richardm-stripe richardm-stripe merged commit 18d6862 into master Aug 29, 2023
21 checks passed
Playgirlkaybrazyworld referenced this pull request Aug 29, 2023
* Change github workflow

* Update Makefile

* Update tests/Stripe/GeneratedExamplesTest.php

* Update Makefile

* Yaml sucks

---------

Co-authored-by: pakrym-stripe <[email protected]>
@richardm-stripe
Copy link
Contributor Author

@remi-stripe remi-stripe deleted the richardm-nicer-exception-tostring branch September 28, 2023 23:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide option to retain full stack traces in ApiErrorException
2 participants