{"action":"created","issue":{"url":"https://api.github.com/repos/zendframework/zend-stratigility/issues/50","repository_url":"https://api.github.com/repos/zendframework/zend-stratigility","labels_url":"https://api.github.com/repos/zendframework/zend-stratigility/issues/50/labels{/name}","comments_url":"https://api.github.com/repos/zendframework/zend-stratigility/issues/50/comments","events_url":"https://api.github.com/repos/zendframework/zend-stratigility/issues/50/events","html_url":"https://github.com/zendframework/zend-stratigility/issues/50","id":142380691,"number":50,"title":"Regression on 1.2.0 with Response end","user":{"login":"bakura10","id":1198915,"avatar_url":"https://avatars.githubusercontent.com/u/1198915?v=3","gravatar_id":"","url":"https://api.github.com/users/bakura10","html_url":"https://github.com/bakura10","followers_url":"https://api.github.com/users/bakura10/followers","following_url":"https://api.github.com/users/bakura10/following{/other_user}","gists_url":"https://api.github.com/users/bakura10/gists{/gist_id}","starred_url":"https://api.github.com/users/bakura10/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bakura10/subscriptions","organizations_url":"https://api.github.com/users/bakura10/orgs","repos_url":"https://api.github.com/users/bakura10/repos","events_url":"https://api.github.com/users/bakura10/events{/privacy}","received_events_url":"https://api.github.com/users/bakura10/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":11,"created_at":"2016-03-21T15:19:12Z","updated_at":"2016-03-21T23:06:59Z","closed_at":"2016-03-21T15:42:57Z","body":"Starting from version 1.2, our app stopped working when an error is thrown in the code.\r\n\r\nIn our code, the `FinalHandler` is map to a custom handler:\r\n\r\n```php\r\nclass JsonErrorHandler\r\n{\r\n    public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $err = null)\r\n    {\r\n        if ($err) {\r\n            return $this->handleError($err, $response);\r\n        }\r\n\r\n        if (null === $request->getAttribute(RouteResult::class)) {\r\n            return new JsonResponse(['message' => 'Not Found'], 404);\r\n        }\r\n\r\n        return $response;\r\n    }\r\n\r\n    private function handleError($err, ResponseInterface $response)\r\n    {\r\n        // To avoid security issue, when the error is an exception, we simply display a 500\r\n        if ($err instanceof Exception) {\r\n            return new JsonResponse(['message' => 'An error occurred'], 500);\r\n        }\r\n\r\n        return new JsonResponse(['message' => $response->getReasonPhrase()], $response->getStatusCode());\r\n    }\r\n}\r\n```\r\n\r\nIt used to return a JsonResponse when there was an error, but now it throws the RuntimeException error:\r\n\r\n<img width=\"1677\" alt=\"capture d ecran 2016-03-21 a 16 18 53\" src=\"https://cloud.githubusercontent.com/assets/1198915/13923368/a1b9a49e-ef80-11e5-8808-e9f0b8d0ed5c.png\">\r\n"},"comment":{"url":"https://api.github.com/repos/zendframework/zend-stratigility/issues/comments/199527348","html_url":"https://github.com/zendframework/zend-stratigility/issues/50#issuecomment-199527348","issue_url":"https://api.github.com/repos/zendframework/zend-stratigility/issues/50","id":199527348,"user":{"login":"nesl247","id":1037526,"avatar_url":"https://avatars.githubusercontent.com/u/1037526?v=3","gravatar_id":"","url":"https://api.github.com/users/nesl247","html_url":"https://github.com/nesl247","followers_url":"https://api.github.com/users/nesl247/followers","following_url":"https://api.github.com/users/nesl247/following{/other_user}","gists_url":"https://api.github.com/users/nesl247/gists{/gist_id}","starred_url":"https://api.github.com/users/nesl247/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nesl247/subscriptions","organizations_url":"https://api.github.com/users/nesl247/orgs","repos_url":"https://api.github.com/users/nesl247/repos","events_url":"https://api.github.com/users/nesl247/events{/privacy}","received_events_url":"https://api.github.com/users/nesl247/received_events","type":"User","site_admin":false},"created_at":"2016-03-21T23:06:59Z","updated_at":"2016-03-21T23:06:59Z","body":"@weierophinney I figured out the issue, and it's not a bug I can fix. If `FinalHandler` is called for an error, this bug will always happen because the `SapiEmitterTrait` will inject the `Content-Length` before it emits the response."}}