Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[HttpClient] Parse common API error formats for better exception messages#30559
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
d2477c7 to4380807Comparesrc/Symfony/Component/HttpClient/Exception/HttpExceptionTrait.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/HttpClient/Exception/HttpExceptionTrait.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
nicolas-grekas left a comment• edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Nice! Just one thing: we should skip this logic when$this instanceof RedirectionExceptionInterface I think.
dunglas commentedMar 21, 2019
@nicolas-grekas I would keep it even for 300 exceptions because Hydra allows to provide better messages even for such status codes, and it doesn't hurt:http://www.hydra-cg.com/spec/latest/core/#description-of-http-status-codes-and-errors |
fabpot commentedMar 24, 2019
Thank you@dunglas. |
… exception messages (dunglas)This PR was squashed before being merged into the 4.3-dev branch (closes#30559).Discussion----------[HttpClient] Parse common API error formats for better exception messages| Q | A| ------------- | ---| Branch? | master <!-- see below -->| Bug fix? | no| New feature? | yes <!-- don't forget to update src/**/CHANGELOG.md files -->| BC breaks? | no <!-- seehttps://symfony.com/bc -->| Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->| Tests pass? | yes <!-- please add some, will be required by reviewers -->| Fixed tickets | n/a <!-- #-prefixed issue number(s), if any -->| License | MIT| Doc PR | todo?Use extra details provided by popular error formats following to improve HTTP exception messages.The following formats are supported:* Hydra (default in API Platform)* RFC 7807 (followed by Symfony's [ConstraintViolationListNormalizer](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Serializer/Normalizer/ConstraintViolationListNormalizer.php) and supported by API Platform and Apigility)* JSON:API (because it respects the semantic of the RFC 7807)It allows to write code like the following (here in a test context):```php public function testBadRequest() { $this->expectException(ClientExceptionInterface::class); $this->expectExceptionCode(400); // HTTP status code $this->expectExceptionMessage(<<<ERRORValidation Failedusers: This collection should contain 1 element or more.users: The current logged in user must be part of the users owning this resource.ERROR); $response = (HttpClient::create())->request('POST', 'http://example.com/api/projects', [ 'json' => [ 'name' => 'My project', ], ]); $response->getContent(); }```Port ofapi-platform/core#2608 (comment).Commits-------96df446 [HttpClient] Parse common API error formats for better exception messages
Use extra details provided by popular error formats following to improve HTTP exception messages.
The following formats are supported:
It allows to write code like the following (here in a test context):
Port ofapi-platform/core#2608 (comment).