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

[HttpKernel] normalized HTTP exceptions classes #5862

Closed
wants to merge 1 commit into from

Conversation

fabpot
Copy link
Member

@fabpot fabpot commented Oct 29, 2012

I've removed the code as it is never used.

And I've added the headers argument to all sub-classes.

{
$this->statusCode = $statusCode;
$this->headers = $headers;

parent::__construct($message, $code, $previous);
parent::__construct($message, 0, $previous);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not keep it? I find it quite nice that generic exception handlers can read out the code and get useful info out of it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now, this is always 0.

Also, the list of arguments for the constructors is already quite long, so added something that is never used makes little sense to me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I meant why not use $statusCode in there then?

fabpot added a commit that referenced this pull request Oct 29, 2012
This PR was squashed before being merged into the master branch (closes #5312).

Commits
-------

e0c4d99 [HttpKernel] Additional HTTP exceptions

Discussion
----------

[HttpKernel] Additional HTTP exceptions

I wanted to continue using exceptions for many other types of HTTP 4xx and 5xx status codes, particularly because I like the notion that I can trap the exception based on the type, rather than inspecting HttpException to see what status code it contains. I've decided to contribute these back to the Symfony HttpKernel component, in case others find them useful.

* Bug fix: no
* Feature addition: yes
* Backwards compatibility break: no
* Symfony2 tests pass: yes
* Fixes the following tickets: -
* Todo: -
* License of the code: MIT
* Documentation PR: n/a

This pull request provides the following new HttpKernel Exceptions:

Exception                          | Applicable HTTP Status Code
---------------------------------- | ---------------------------------------
BadRequestHttpException            | `400 Bad Request`
ConflictHttpException              | `409 Conflict`
GoneHttpException                  | `410 Gone`
InternalServerErrorHttpException   | `500 Internal Server Error`
LengthRequiredHttpException        | `411 Length Required`
NotAcceptableHttpException         | `406 Not Acceptable`
PreconditionFailedHttpException    | `412 Precondition Failed`
PreconditionRequiredHttpException  | `428 Precondition Required`†
ServiceUnavailableHttpException    | `503 Service Unavailable`
TooManyRequestsHttpException       | `429 Too Many Requests`†
UnauthorizedHttpException          | `401 Unauthorized`
UnsupportedMediaTypeHttpException  | `415 Unsupported Media Type`

All the tests have been placed in the FlattenExceptionTest, since that's where the previous status code and method tests for HttpException exceptions are located, but I can move them to a more logical location, if needed.

† These codes have been included from [RFC 6585, Additional HTTP Status Codes](http://tools.ietf.org/html/rfc6585).

---------------------------------------------------------------------------

by stof at 2012-08-21T23:10:45Z

I would remove the InternalServerError one, as you get a 500 for any non-http exception anyway

---------------------------------------------------------------------------

by stof at 2012-08-21T23:11:34Z

and please rebase your branch to get rid of the merge commit at the beginning of your PR

---------------------------------------------------------------------------

by ramsey at 2012-10-03T20:22:59Z

@stof Can you provide some pointers on how to get rid of the merge commit through a rebase? I generally avoid rebase, so doing this is fairly new to me. I realize that what created the commit was a non-fast-forward merge, so I just need to understand how to get it to apply merges cleanly without creating merge commits like that. Thanks!

---------------------------------------------------------------------------

by alexandresalome at 2012-10-04T07:14:00Z

@ramsey

    # suppose you are on branch-feature
    # given origin is the symfony repository
    git pull --rebase origin/master

    # equivalent to
    git fetch origin
    git rebase origin/master

If you want to rebase your branch on 2.1:

    git pull --rebase origin/2.1

---------------------------------------------------------------------------

by stof at 2012-10-04T18:52:22Z

@ramsey http://symfony.com/doc/current/contributing/code/patches.html#rework-your-patch for the documentation about the way to do it

---------------------------------------------------------------------------

by stof at 2012-10-13T20:44:26Z

@ramsey ping

---------------------------------------------------------------------------

by fabpot at 2012-10-29T09:47:36Z

I'm going to finish this PR, but #5862 should be merged first.

---------------------------------------------------------------------------

by ramsey at 2012-10-29T15:36:31Z

Sorry I've been sitting on this for so long. I haven't had time to figure out how to get rid of the merge commit, as @stof requested. That's the only outstanding issue here, as far as I know.

---------------------------------------------------------------------------

by fabpot at 2012-10-29T15:47:54Z

I can see another issue. For some HTTP codes, you can/should/must add some headers or some content (like for the 406 status code).

Don't worry about the merge commit or the rebasing, I will take care of that myself when merging the PR.

---------------------------------------------------------------------------

by ramsey at 2012-10-29T16:05:04Z

I don't know what header is required for the 406 status code. RFC 2616 doesn't specify one. It does say "the response should include an entity containing a list of available entity characteristics and locations."

In other exceptions, such as UnauthorizedHttpException, TooManyRequestsHttpException, and ServiceUnavailableException, I did provide the required headers.

On Monday, October 29, 2012 at 10:48 AM, Fabien Potencier wrote:

> I can see another issue. For some HTTP codes, you can/should/must add some headers or some content (like for the 406 status code).
> Don't worry about the merge commit or the rebasing, I will take care of that myself when merging the PR.
>
> —
> Reply to this email directly or view it on GitHub (#5312 (comment)).
>
>
>
@fabpot
Copy link
Member Author

fabpot commented Oct 29, 2012

This PR must be updated now that #5312 has been merged.

@fabpot fabpot closed this Mar 23, 2013
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.

None yet

2 participants