Skip to content

Commit

Permalink
Merge pull request #125 from tarjei/readme
Browse files Browse the repository at this point in the history
Add more info about the exception handler to the Readme
  • Loading branch information
lsmith77 committed Sep 8, 2011
2 parents 1ea5450 + 2598c03 commit c6f504d
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion README.md
Expand Up @@ -402,7 +402,7 @@ ExceptionController support
Using this custom ExceptionController it is possible to leverage the View layer Using this custom ExceptionController it is possible to leverage the View layer
when building responses for uncaught Exceptions. when building responses for uncaught Exceptions.


The RestBundle view-layer-aware ExceptionController is enabled as follows: To enable the RestBundle view-layer-aware ExceptionController update the framework section of your config like this:


```yaml ```yaml
# app/config/config.yml # app/config/config.yml
Expand All @@ -425,6 +425,25 @@ fos_rest:
'Acme\HelloBundle\Exception\MyExceptionWithASafeMessage': true 'Acme\HelloBundle\Exception\MyExceptionWithASafeMessage': true
``` ```


If you want to display the message from the exception in the content of the response, add the
exception to the messages map as well. If not only the statuscode will be returned.

If you know what status code you want to return you do not have to add a mapping, you can do
this in your controller:

```php
<?php
class UsersController extends Controller
{
public function postUserCommentsAction($slug)
{
if (!$this->validate($slug)) {
throw new HttpException(400, "New comment is not valid.");
}
}
}
```

See the following example configuration for more details: See the following example configuration for more details:
https://github.com/lsmith77/symfony-standard/blob/techtalk/app/config/config.yml https://github.com/lsmith77/symfony-standard/blob/techtalk/app/config/config.yml


Expand Down

0 comments on commit c6f504d

Please sign in to comment.