-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[HttpFoundation] Add ProblemDetailsJsonResponse
for HTTP APIs
#61208
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
base: 7.4
Are you sure you want to change the base?
[HttpFoundation] Add ProblemDetailsJsonResponse
for HTTP APIs
#61208
Conversation
Hey! I see that this is your first PR. That is great! Welcome! Symfony has a contribution guide which I suggest you to read. In short:
Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change. When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor! I am going to sit back now and wait for the reviews. Cheers! Carsonbot |
2bbb577
to
7cecc40
Compare
src/Symfony/Component/HttpFoundation/ProblemDetailJsonResponse.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/HttpFoundation/ProblemDetailJsonResponse.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/HttpFoundation/ProblemDetailJsonResponse.php
Outdated
Show resolved
Hide resolved
Thank you very much @smnandre |
src/Symfony/Component/HttpFoundation/Exception/ProblemDetailJsonResponseException.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/HttpFoundation/ProblemDetailJsonResponse.php
Outdated
Show resolved
Hide resolved
Thank you @OskarStark |
Problem Details for HTTP APIs
ProblemDetailJsonResponse
for HTTP APIs
ProblemDetailJsonResponse
for HTTP APIsProblemDetailsJsonResponse
for HTTP APIs
src/Symfony/Component/HttpFoundation/ProblemDetailJsonResponse.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/HttpFoundation/Exception/ProblemDetailJsonResponseException.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/HttpFoundation/ProblemDetailJsonResponse.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/HttpFoundation/Tests/ProblemDetailJsonResponseTest.php
Outdated
Show resolved
Hide resolved
This feature adds more detail to the HTTP response errors as specified by RFC 7807 and completed by RFC 9457
….php Co-authored-by: Simon André <smn.andre@gmail.com>
….php Co-authored-by: Simon André <smn.andre@gmail.com>
…onResponseException.php Co-authored-by: Oskar Stark <oskarstark@googlemail.com>
….php Co-authored-by: Oskar Stark <oskarstark@googlemail.com>
Co-authored-by: Oskar Stark <oskarstark@googlemail.com>
8befed4
to
a51dabd
Compare
The RFC also supports “errors”. Would it make sense to also support these in the class? |
Great. I missed that one because I was only scanning for „error“. |
/** | ||
* @author Abdellah Ramadan <ramadanabdel24@gmail.com> | ||
*/ | ||
class ProblemDetailsJsonResponseException extends \Exception |
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.
Can we be more specific for the class we extend?
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.
Okay @OskarStark.
As a first timer, I am still trying to get things right. Should I get rid of the entire exception class?
* @throws ProblemDetailsJsonResponseException | ||
* @throws \JsonException | ||
*/ | ||
protected function setProblemContent(): string |
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.
any reason to not make it private?
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.
No reason. I can make it private.
public function testNewProblemWithNoParams() | ||
{ | ||
$problemDetails = new ProblemDetailsJsonResponse(); | ||
$this->assertEquals(520, $problemDetails->getStatusCode()); |
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.
assertSame wherever possible please
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.
Noted.
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.
I feel like everything should be in the constructor, or, if we split in methods, computed lazily (but not sure that'd be useful here)
src/Symfony/Component/HttpFoundation/Tests/ProblemDetailsJsonResponseTest.php
Outdated
Show resolved
Hide resolved
$this->setProblemContent(); | ||
} | ||
|
||
private function setHeaders(): void |
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.
we should get rid of those unusual private setters IMHO
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.
Okay @nicolas-grekas.
I am doing that then.
* @throws ProblemDetailsJsonResponseException | ||
* @throws \JsonException | ||
*/ | ||
protected function setProblemContent(): string |
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.
protected means this is an extension point. I don't think that's legit.
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.
Should it be made private?
Sorry for being silly on this one. Still trying to get everything right.
…esponseTest.php Co-authored-by: Nicolas Grekas <nicolas.grekas@gmail.com>
This PR introduces the
ProblemDetailJsonResponse
which is an implementation of RFC 9457 to describe the specifics of a problem encountered: