Error pages do not match content type / format

I followed this guide http://symfony.com/doc/current/cookbook/controller/error_pages.html and had error.html.twig and error.json.twig in app / Resources / TwigBundle / views / Exception /

Although an application / json is specified for the request content type, all errors by default correspond to the html version of the error page.

The route format is also defined: http: //symfonyinstall/api/v1/users.json

Request Header:

Accept: application/json
Content-Type: application/json
Connection: keep-alive
Origin: chrome-extension: //rest-console-id
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko)           Chrome/18.0.1025.162 Safari/535.19

Answer Header:

Status Code: 404
date: Sun, 29 Apr 2012 06:54:35 GMT
Content-Encoding: gzip
X-Powered-By: PHP/5.3.10
Transfer-Encoding: chunked
Connection: keep-alive
Server: nginx
Content-Type: text/html; charset=UTF-8
cache-control: no-cache

I have no ideas ... and I really need the json version for errors for my API ...

+2
source share
1 answer

, , Symfony , - , , , , - .

, , . , , , . , , , , ( :).

JsonResponse , Content-Type: text/html; charset=UTF-8. , netcat, - , , Content-Type:

HTTP/1.0 500 Internal Server Error
Connection: close
X-Powered-By: PHP/5.5.9-1ubuntu4.17
Content-Type: text/html; charset=UTF-8
Cache-Control: private, must-revalidate
Content-Type: application/json
pragma: no-cache
expires: -1
X-Debug-Token: 775c55
X-Debug-Token-Link: http://127.0.0.1:8000/_profiler/775c55
Date: Thu, 27 Oct 2016 23:08:31 GMT

Content-Type -, . , Symfony\Component\Debug\ExceptionHandler, . , Symfony, . , PHP . . , .

, - . , WebAPI, , , . , , WebAPI, , , .

Symfony . symfony . , . - , , , ? , ob_ *?

0

Source: https://habr.com/ru/post/1626103/


All Articles