{"action":"created","comment":{"url":"https://api.github.com/repos/slimphp/Slim/pulls/comments/168633356","pull_request_review_id":97035876,"id":168633356,"diff_hunk":"@@ -0,0 +1,122 @@\n+<?php\n+namespace Slim\\Exception;\n+\n+use Psr\\Http\\Message\\ResponseInterface;\n+use Psr\\Http\\Message\\ServerRequestInterface;\n+\n+abstract class HttpException extends \\Exception\n+{\n+    /**\n+     * @var ServerRequestInterface|null\n+     */\n+    protected $request = null;\n+    /**\n+     * @var ResponseInterface|null\n+     */\n+    protected $response = null;\n+    /**\n+     * @var array|null\n+     */\n+    protected $details;\n+    /**\n+     * @var string|null\n+     */\n+    protected $title = '';\n+    /**\n+     * @var string\n+     */\n+    protected $description = '';\n+\n+    /**\n+     * HttpException constructor.\n+     * @param string|array|null $details\n+     */\n+    public function __construct($details = null)\n+    {\n+        if (is_string($details)) {\n+            parent::__construct($details);","path":"Slim/Exception/HttpException.php","position":37,"original_position":37,"commit_id":"e34b6a7b11a2b9ca1c1dce3233af0fdc2ad83079","original_commit_id":"e34b6a7b11a2b9ca1c1dce3233af0fdc2ad83079","user":{"login":"asheliahut","id":945619,"avatar_url":"https://avatars3.githubusercontent.com/u/945619?v=4","gravatar_id":"","url":"https://api.github.com/users/asheliahut","html_url":"https://github.com/asheliahut","followers_url":"https://api.github.com/users/asheliahut/followers","following_url":"https://api.github.com/users/asheliahut/following{/other_user}","gists_url":"https://api.github.com/users/asheliahut/gists{/gist_id}","starred_url":"https://api.github.com/users/asheliahut/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asheliahut/subscriptions","organizations_url":"https://api.github.com/users/asheliahut/orgs","repos_url":"https://api.github.com/users/asheliahut/repos","events_url":"https://api.github.com/users/asheliahut/events{/privacy}","received_events_url":"https://api.github.com/users/asheliahut/received_events","type":"User","site_admin":false},"body":"you can just return the parent constructor otherwise do $this->details = $details\r\nthus removing the else.","created_at":"2018-02-15T22:52:43Z","updated_at":"2018-02-15T22:54:04Z","html_url":"https://github.com/slimphp/Slim/pull/2398#discussion_r168633356","pull_request_url":"https://api.github.com/repos/slimphp/Slim/pulls/2398","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/slimphp/Slim/pulls/comments/168633356"},"html":{"href":"https://github.com/slimphp/Slim/pull/2398#discussion_r168633356"},"pull_request":{"href":"https://api.github.com/repos/slimphp/Slim/pulls/2398"}}},"pull_request":{"url":"https://api.github.com/repos/slimphp/Slim/pulls/2398","id":169187460,"html_url":"https://github.com/slimphp/Slim/pull/2398","diff_url":"https://github.com/slimphp/Slim/pull/2398.diff","patch_url":"https://github.com/slimphp/Slim/pull/2398.patch","issue_url":"https://api.github.com/repos/slimphp/Slim/issues/2398","number":2398,"state":"open","locked":false,"title":"4.x Error Middleware","user":{"login":"l0gicgate","id":6510935,"avatar_url":"https://avatars2.githubusercontent.com/u/6510935?v=4","gravatar_id":"","url":"https://api.github.com/users/l0gicgate","html_url":"https://github.com/l0gicgate","followers_url":"https://api.github.com/users/l0gicgate/followers","following_url":"https://api.github.com/users/l0gicgate/following{/other_user}","gists_url":"https://api.github.com/users/l0gicgate/gists{/gist_id}","starred_url":"https://api.github.com/users/l0gicgate/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/l0gicgate/subscriptions","organizations_url":"https://api.github.com/users/l0gicgate/orgs","repos_url":"https://api.github.com/users/l0gicgate/repos","events_url":"https://api.github.com/users/l0gicgate/events{/privacy}","received_events_url":"https://api.github.com/users/l0gicgate/received_events","type":"User","site_admin":false},"body":"**Preface**\r\nThe original PR #2222 was closed and some of the concepts and code will be implemented in this PR. \r\n\r\n**Description**\r\nThis PR eliminates all native error handlers and replaces it with `ErrorMiddleware` which handles all errors and provides multiple different renderers (HTML, XML, JSON, Plain Text) to enhance error display.\r\n\r\n**Implementation**\r\n```php\r\nuse Slim\\App;\r\nuse Slim\\Middleware\\ErrorMiddleware;\r\nuse Slim\\Middleware\\RoutingMiddleware;\r\n\r\n$app = new App();\r\n\r\n/*\r\n * The routing middleware should always be added first\r\n * before the error handling middleware is added\r\n */\r\n$routingMiddleware = new RoutingMiddleware($app->getRouter());\r\n$app->add($routingMiddleware);\r\n\r\n/*\r\n * The constructor of `ErrorMiddleware` takes in 2 parameters\r\n * @param bool $displayErrorDetails -> Should be set to false in production\r\n * @param bool $defaultErrorHandler -> By default Slim provides a proprietary error handler\r\n * which can be replaced by a callable of your choice.\r\n */\r\n$errorMiddleware = new ErrorMiddleware(false);\r\n$app->add($errorMiddleware);\r\n\r\n...\r\n$app->run();\r\n```\r\n\r\n**Adding custom handlers for different named exceptions**\r\n```php\r\n...\r\n$errorMiddleware = new ErrorMiddleware(false);\r\n\r\n$handler = function ($req, $res, $exception, $displayErrorDetails) {\r\n    return $res->withJson(['error' => 'Caught MyNamedException']);\r\n}\r\n$errorMiddleware->setErrorHandler(MyNamedException::class, $handler);\r\n$app->add($errorMiddleware);\r\n````\r\n\r\n**Error Handling/Rendering**\r\nThe rendering is finally decoupled from the handling. Everything still works the way it previously did. It will still detect the content-type and render things appropriately with the help of `ErrorRenderers`. The core `ErrorHandler` extends the `AbstractErrorHandler` class which has been completely refactored. By default it will call the appropriate `ErrorRenderer` for the supported content types. Someone can now provide their custom error renderer by extending the `AbstractErrorHandler` class and overloading the protected `renderer` variable from the parent. \r\n\r\n```php\r\nclass MyCustomErrorRenderer extends \\Slim\\Handlers\\AbstractErrorRenderer\r\n{\r\n    public function render()\r\n    {\r\n        return 'My awesome format';\r\n    }\r\n}\r\n\r\nclass MyCustomErrorHandler extends \\Slim\\Handlers\\AbstractErrorHandler\r\n{\r\n    protected $renderer = MyCustomErrorRenderer::class;\r\n}\r\n```\r\n\r\n**HTTP Exceptions**\r\nI just think it makes sense to throw HTTP based exceptions within the application. These exceptions works with nicely with the proposed native renderers. They can each have a `description` and `title` attribute as well to provide a bit more insight when the native HTML renderer is invoked. \r\n\r\nThe base class `HttpException` extends `Exception` and comes with the following sub classes :\r\n- `HttpBadGatewayException`\r\n- `HttpBadRequestException`\r\n- `HttpForbiddenException`\r\n- `HttpInternalServerErrorException`\r\n- `HttpNotAllowedException`\r\n- `HttpNotFoundException`\r\n- `HttpNotImplementedException`\r\n- `HttpUnauthorizedException`\r\n\r\nThe developer can extend the `HttpException` class if they need any other response codes that we decide not to provide with the base repository. Example if you wanted a 504 gateway timeout exception that behaves like the native ones you would do the following:\r\nI\r\n```php\r\nclass HttpForbiddenException extends HttpException\r\n{\r\n    protected $code = 504;\r\n    protected $message = 'Gateway Timeout.';\r\n    protected $title = '504 Gateway Timeout';\r\n    protected $description = 'Timed out before receiving response from the upstream server.';\r\n}\r\n```\r\n\r\n**Status**\r\nWork in progress\r\n- [x] Remove Existing Error Handling\r\n- [X] Implement Error Middleware\r\n- [X] Implement supporting tests\r\n- [ ] Discussion and Code Review.","created_at":"2018-02-14T18:30:32Z","updated_at":"2018-02-15T22:54:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d5650d9f625a0110c51eb98038c119896794849e","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/slimphp/Slim/pulls/2398/commits","review_comments_url":"https://api.github.com/repos/slimphp/Slim/pulls/2398/comments","review_comment_url":"https://api.github.com/repos/slimphp/Slim/pulls/comments{/number}","comments_url":"https://api.github.com/repos/slimphp/Slim/issues/2398/comments","statuses_url":"https://api.github.com/repos/slimphp/Slim/statuses/e34b6a7b11a2b9ca1c1dce3233af0fdc2ad83079","head":{"label":"l0gicgate:4.x-ErrorMiddleware","ref":"4.x-ErrorMiddleware","sha":"e34b6a7b11a2b9ca1c1dce3233af0fdc2ad83079","user":{"login":"l0gicgate","id":6510935,"avatar_url":"https://avatars2.githubusercontent.com/u/6510935?v=4","gravatar_id":"","url":"https://api.github.com/users/l0gicgate","html_url":"https://github.com/l0gicgate","followers_url":"https://api.github.com/users/l0gicgate/followers","following_url":"https://api.github.com/users/l0gicgate/following{/other_user}","gists_url":"https://api.github.com/users/l0gicgate/gists{/gist_id}","starred_url":"https://api.github.com/users/l0gicgate/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/l0gicgate/subscriptions","organizations_url":"https://api.github.com/users/l0gicgate/orgs","repos_url":"https://api.github.com/users/l0gicgate/repos","events_url":"https://api.github.com/users/l0gicgate/events{/privacy}","received_events_url":"https://api.github.com/users/l0gicgate/received_events","type":"User","site_admin":false},"repo":{"id":90817003,"name":"Slim","full_name":"l0gicgate/Slim","owner":{"login":"l0gicgate","id":6510935,"avatar_url":"https://avatars2.githubusercontent.com/u/6510935?v=4","gravatar_id":"","url":"https://api.github.com/users/l0gicgate","html_url":"https://github.com/l0gicgate","followers_url":"https://api.github.com/users/l0gicgate/followers","following_url":"https://api.github.com/users/l0gicgate/following{/other_user}","gists_url":"https://api.github.com/users/l0gicgate/gists{/gist_id}","starred_url":"https://api.github.com/users/l0gicgate/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/l0gicgate/subscriptions","organizations_url":"https://api.github.com/users/l0gicgate/orgs","repos_url":"https://api.github.com/users/l0gicgate/repos","events_url":"https://api.github.com/users/l0gicgate/events{/privacy}","received_events_url":"https://api.github.com/users/l0gicgate/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/l0gicgate/Slim","description":"Slim Framework source code","fork":true,"url":"https://api.github.com/repos/l0gicgate/Slim","forks_url":"https://api.github.com/repos/l0gicgate/Slim/forks","keys_url":"https://api.github.com/repos/l0gicgate/Slim/keys{/key_id}","collaborators_url":"https://api.github.com/repos/l0gicgate/Slim/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/l0gicgate/Slim/teams","hooks_url":"https://api.github.com/repos/l0gicgate/Slim/hooks","issue_events_url":"https://api.github.com/repos/l0gicgate/Slim/issues/events{/number}","events_url":"https://api.github.com/repos/l0gicgate/Slim/events","assignees_url":"https://api.github.com/repos/l0gicgate/Slim/assignees{/user}","branches_url":"https://api.github.com/repos/l0gicgate/Slim/branches{/branch}","tags_url":"https://api.github.com/repos/l0gicgate/Slim/tags","blobs_url":"https://api.github.com/repos/l0gicgate/Slim/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/l0gicgate/Slim/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/l0gicgate/Slim/git/refs{/sha}","trees_url":"https://api.github.com/repos/l0gicgate/Slim/git/trees{/sha}","statuses_url":"https://api.github.com/repos/l0gicgate/Slim/statuses/{sha}","languages_url":"https://api.github.com/repos/l0gicgate/Slim/languages","stargazers_url":"https://api.github.com/repos/l0gicgate/Slim/stargazers","contributors_url":"https://api.github.com/repos/l0gicgate/Slim/contributors","subscribers_url":"https://api.github.com/repos/l0gicgate/Slim/subscribers","subscription_url":"https://api.github.com/repos/l0gicgate/Slim/subscription","commits_url":"https://api.github.com/repos/l0gicgate/Slim/commits{/sha}","git_commits_url":"https://api.github.com/repos/l0gicgate/Slim/git/commits{/sha}","comments_url":"https://api.github.com/repos/l0gicgate/Slim/comments{/number}","issue_comment_url":"https://api.github.com/repos/l0gicgate/Slim/issues/comments{/number}","contents_url":"https://api.github.com/repos/l0gicgate/Slim/contents/{+path}","compare_url":"https://api.github.com/repos/l0gicgate/Slim/compare/{base}...{head}","merges_url":"https://api.github.com/repos/l0gicgate/Slim/merges","archive_url":"https://api.github.com/repos/l0gicgate/Slim/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/l0gicgate/Slim/downloads","issues_url":"https://api.github.com/repos/l0gicgate/Slim/issues{/number}","pulls_url":"https://api.github.com/repos/l0gicgate/Slim/pulls{/number}","milestones_url":"https://api.github.com/repos/l0gicgate/Slim/milestones{/number}","notifications_url":"https://api.github.com/repos/l0gicgate/Slim/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/l0gicgate/Slim/labels{/name}","releases_url":"https://api.github.com/repos/l0gicgate/Slim/releases{/id}","deployments_url":"https://api.github.com/repos/l0gicgate/Slim/deployments","created_at":"2017-05-10T03:28:31Z","updated_at":"2017-05-19T02:03:07Z","pushed_at":"2018-02-15T09:17:34Z","git_url":"git://github.com/l0gicgate/Slim.git","ssh_url":"git@github.com:l0gicgate/Slim.git","clone_url":"https://github.com/l0gicgate/Slim.git","svn_url":"https://github.com/l0gicgate/Slim","homepage":"http://slimframework.com","size":5508,"stargazers_count":1,"watchers_count":1,"language":"PHP","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":1,"default_branch":"3.x"}},"base":{"label":"slimphp:4.x","ref":"4.x","sha":"bd6ef95fb99357ea1c03260b2715f085eeac3f0a","user":{"login":"slimphp","id":11195762,"avatar_url":"https://avatars1.githubusercontent.com/u/11195762?v=4","gravatar_id":"","url":"https://api.github.com/users/slimphp","html_url":"https://github.com/slimphp","followers_url":"https://api.github.com/users/slimphp/followers","following_url":"https://api.github.com/users/slimphp/following{/other_user}","gists_url":"https://api.github.com/users/slimphp/gists{/gist_id}","starred_url":"https://api.github.com/users/slimphp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/slimphp/subscriptions","organizations_url":"https://api.github.com/users/slimphp/orgs","repos_url":"https://api.github.com/users/slimphp/repos","events_url":"https://api.github.com/users/slimphp/events{/privacy}","received_events_url":"https://api.github.com/users/slimphp/received_events","type":"Organization","site_admin":false},"repo":{"id":926544,"name":"Slim","full_name":"slimphp/Slim","owner":{"login":"slimphp","id":11195762,"avatar_url":"https://avatars1.githubusercontent.com/u/11195762?v=4","gravatar_id":"","url":"https://api.github.com/users/slimphp","html_url":"https://github.com/slimphp","followers_url":"https://api.github.com/users/slimphp/followers","following_url":"https://api.github.com/users/slimphp/following{/other_user}","gists_url":"https://api.github.com/users/slimphp/gists{/gist_id}","starred_url":"https://api.github.com/users/slimphp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/slimphp/subscriptions","organizations_url":"https://api.github.com/users/slimphp/orgs","repos_url":"https://api.github.com/users/slimphp/repos","events_url":"https://api.github.com/users/slimphp/events{/privacy}","received_events_url":"https://api.github.com/users/slimphp/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/slimphp/Slim","description":"Slim Framework source code","fork":false,"url":"https://api.github.com/repos/slimphp/Slim","forks_url":"https://api.github.com/repos/slimphp/Slim/forks","keys_url":"https://api.github.com/repos/slimphp/Slim/keys{/key_id}","collaborators_url":"https://api.github.com/repos/slimphp/Slim/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/slimphp/Slim/teams","hooks_url":"https://api.github.com/repos/slimphp/Slim/hooks","issue_events_url":"https://api.github.com/repos/slimphp/Slim/issues/events{/number}","events_url":"https://api.github.com/repos/slimphp/Slim/events","assignees_url":"https://api.github.com/repos/slimphp/Slim/assignees{/user}","branches_url":"https://api.github.com/repos/slimphp/Slim/branches{/branch}","tags_url":"https://api.github.com/repos/slimphp/Slim/tags","blobs_url":"https://api.github.com/repos/slimphp/Slim/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/slimphp/Slim/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/slimphp/Slim/git/refs{/sha}","trees_url":"https://api.github.com/repos/slimphp/Slim/git/trees{/sha}","statuses_url":"https://api.github.com/repos/slimphp/Slim/statuses/{sha}","languages_url":"https://api.github.com/repos/slimphp/Slim/languages","stargazers_url":"https://api.github.com/repos/slimphp/Slim/stargazers","contributors_url":"https://api.github.com/repos/slimphp/Slim/contributors","subscribers_url":"https://api.github.com/repos/slimphp/Slim/subscribers","subscription_url":"https://api.github.com/repos/slimphp/Slim/subscription","commits_url":"https://api.github.com/repos/slimphp/Slim/commits{/sha}","git_commits_url":"https://api.github.com/repos/slimphp/Slim/git/commits{/sha}","comments_url":"https://api.github.com/repos/slimphp/Slim/comments{/number}","issue_comment_url":"https://api.github.com/repos/slimphp/Slim/issues/comments{/number}","contents_url":"https://api.github.com/repos/slimphp/Slim/contents/{+path}","compare_url":"https://api.github.com/repos/slimphp/Slim/compare/{base}...{head}","merges_url":"https://api.github.com/repos/slimphp/Slim/merges","archive_url":"https://api.github.com/repos/slimphp/Slim/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/slimphp/Slim/downloads","issues_url":"https://api.github.com/repos/slimphp/Slim/issues{/number}","pulls_url":"https://api.github.com/repos/slimphp/Slim/pulls{/number}","milestones_url":"https://api.github.com/repos/slimphp/Slim/milestones{/number}","notifications_url":"https://api.github.com/repos/slimphp/Slim/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/slimphp/Slim/labels{/name}","releases_url":"https://api.github.com/repos/slimphp/Slim/releases{/id}","deployments_url":"https://api.github.com/repos/slimphp/Slim/deployments","created_at":"2010-09-21T01:17:06Z","updated_at":"2018-02-15T17:44:44Z","pushed_at":"2018-02-15T09:17:38Z","git_url":"git://github.com/slimphp/Slim.git","ssh_url":"git@github.com:slimphp/Slim.git","clone_url":"https://github.com/slimphp/Slim.git","svn_url":"https://github.com/slimphp/Slim","homepage":"http://slimframework.com","size":5468,"stargazers_count":8710,"watchers_count":8710,"language":"PHP","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1717,"mirror_url":null,"archived":false,"open_issues_count":66,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":1717,"open_issues":66,"watchers":8710,"default_branch":"3.x"}},"_links":{"self":{"href":"https://api.github.com/repos/slimphp/Slim/pulls/2398"},"html":{"href":"https://github.com/slimphp/Slim/pull/2398"},"issue":{"href":"https://api.github.com/repos/slimphp/Slim/issues/2398"},"comments":{"href":"https://api.github.com/repos/slimphp/Slim/issues/2398/comments"},"review_comments":{"href":"https://api.github.com/repos/slimphp/Slim/pulls/2398/comments"},"review_comment":{"href":"https://api.github.com/repos/slimphp/Slim/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/slimphp/Slim/pulls/2398/commits"},"statuses":{"href":"https://api.github.com/repos/slimphp/Slim/statuses/e34b6a7b11a2b9ca1c1dce3233af0fdc2ad83079"}},"author_association":"NONE"}}
{"actor":{"display_login":"asheliahut"}}