Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[TwigBundle] Add Content-Type header for exception response #23052

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

Merged
merged 1 commit into from
Jun 16, 2017
Merged

[TwigBundle] Add Content-Type header for exception response #23052

merged 1 commit into from
Jun 16, 2017

Conversation

rchoquet
Copy link

@rchoquet rchoquet commented Jun 3, 2017

Q A
Branch? 2.7
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR

This PR comes after I was looking to customize the way exceptions are served for a JSON API (grabbed the info at http://symfony.com/doc/current/controller/error_pages.html#overriding-the-default-exceptioncontroller).

I noticed that even when changing the request format to 'json' so that the right json.twig template is served:

// in my override of the ExceptionController
public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null)
{
    $request->setRequestFormat('json');
    return parent::showAction($request, $exception, $logger);
}

the response Content-Type header was still 'text/html'.

By now, the response Content-Type should be corresponding to the given request format.

I also feel there's some room for improvement with the general "displaying error for a JSON API" chapter as it feels strange that there's no configuration option to just say "serve me anything as json", but that's another issue.

@rchoquet rchoquet changed the base branch from master to 3.2 June 3, 2017 18:41
@nicolas-grekas nicolas-grekas added this to the 3.2 milestone Jun 4, 2017
@fabpot
Copy link
Member

fabpot commented Jun 14, 2017

Don't we have the same issue on 2.7 and 2.8? If yes, then could you rebase this PR on 2.7? Thanks.

@rchoquet rchoquet changed the base branch from 3.2 to 2.7 June 15, 2017 09:47
@rchoquet
Copy link
Author

@fabpot yep my bad, done.

@fabpot
Copy link
Member

fabpot commented Jun 16, 2017

Thank you @rchoquet.

@fabpot fabpot merged commit 9e2b408 into symfony:2.7 Jun 16, 2017
fabpot added a commit that referenced this pull request Jun 16, 2017
…e (rchoquet)

This PR was merged into the 2.7 branch.

Discussion
----------

[TwigBundle] Add Content-Type header for exception response

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

This PR comes after I was looking to customize the way exceptions are served for a JSON API (grabbed the info at http://symfony.com/doc/current/controller/error_pages.html#overriding-the-default-exceptioncontroller).

I noticed that even when changing the request format to 'json' so that the right json.twig template is served:
```php
// in my override of the ExceptionController
public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null)
{
    $request->setRequestFormat('json');
    return parent::showAction($request, $exception, $logger);
}
```
the response Content-Type header was still 'text/html'.

By now, the response Content-Type should be corresponding to the given request format.

I also feel there's some room for improvement with the general "displaying error for a JSON API" chapter as it feels strange that there's no configuration option to just say "serve me anything as json", but that's another issue.

Commits
-------

9e2b408 add content-type header on exception response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants