This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
Go to file
Fabien Potencier 27ee8468fe merged branch ramsey/feature/additional-http-exceptions (PR #5312)
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 (https://github.com/symfony/symfony/pull/5312#issuecomment-9871877).
>
>
>
2012-10-29 17:12:57 +01:00
src/Symfony [HttpKernel] added some more HTTP exceptions 2012-10-29 17:11:00 +01:00
.editorconfig Add EditorConfig File 2012-06-16 14:08:15 +02:00
.gitignore ignore composer.phar 2012-04-20 14:10:06 +01:00
.travis.yml Merge branch '2.1' 2012-09-20 10:40:30 +02:00
autoload.php.dist removed manual locale stub autoload 2012-10-03 13:58:05 +03:00
CHANGELOG-2.0.md updated CHANGELOG for 2.0.18 2012-10-25 10:56:03 +02:00
CHANGELOG-2.1.md updated CHANGELOG for 2.1.2 2012-09-20 09:12:35 +02:00
composer.json Merge branch '2.1' 2012-10-18 23:16:19 +02:00
CONTRIBUTING.md Create CONTRIBUTING.md file for auto-linking in PR's 2012-09-17 14:40:53 -04:00
CONTRIBUTORS.md update CONTRIBUTORS for 2.0.18 2012-10-25 10:56:32 +02:00
LICENSE Updated LICENSE files copyright 2012-02-22 10:10:37 +01:00
phpunit.xml.dist [Locale] Fixed tests 2012-09-24 10:11:13 +02:00
README.md Point to information on how to run the test suite. (closes #5405) 2012-09-01 08:52:18 +02:00
UPGRADE-2.1.md Remove § about prototype_name customization in 2.0 2012-10-25 10:33:18 +02:00

README

Build Status

What is Symfony2?

Symfony2 is a PHP 5.3 full-stack web framework. It is written with speed and flexibility in mind. It allows developers to build better and easy to maintain websites with PHP.

Symfony can be used to develop all kind of websites, from your personal blog to high traffic ones like Dailymotion or Yahoo! Answers.

Requirements

Symfony2 is only supported on PHP 5.3.3 and up.

Be warned that PHP versions before 5.3.8 are known to be buggy and might not work for you:

Installation

The best way to install Symfony2 is to download the Symfony Standard Edition available at http://symfony.com/download.

Documentation

The "Quick Tour" tutorial gives you a first feeling of the framework. If, like us, you think that Symfony2 can help speed up your development and take the quality of your work to the next level, read the official Symfony2 documentation.

Contributing

Symfony2 is an open source, community-driven project. If you'd like to contribute, please read the Contributing Code part of the documentation. If you're submitting a pull request, please follow the guidelines in the Submitting a Patch section.

Running Symfony2 Tests

Information on how to run the Symfony2 test suite can be found in the Running Symfony2 Tests section.