我遵循了本教程http://symfony.com/doc/current/cookbook/controller/error_pages.html,并且在 app/Resources/TwigBundle/views/Exception/ 中有 error.html.twig 和 error.json.twig
即使请求的内容类型设置为 application/json,所有错误都默认为错误页面的 html 版本。
路由的格式也定义了: http://symfonyinstall/api/v1/users.json
请求标头:
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
响应标头:
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
我没有想法......我真的需要一个 json 版本的错误才能让我的 API 工作......