{"action":"closed","issue":{"url":"https://api.github.com/repos/slimphp/Slim/issues/965","labels_url":"https://api.github.com/repos/slimphp/Slim/issues/965/labels{/name}","comments_url":"https://api.github.com/repos/slimphp/Slim/issues/965/comments","events_url":"https://api.github.com/repos/slimphp/Slim/issues/965/events","html_url":"https://github.com/slimphp/Slim/issues/965","id":52199174,"number":965,"title":"Bug with notFound()","user":{"login":"sjl2024","id":939825,"avatar_url":"https://avatars.githubusercontent.com/u/939825?v=3","gravatar_id":"","url":"https://api.github.com/users/sjl2024","html_url":"https://github.com/sjl2024","followers_url":"https://api.github.com/users/sjl2024/followers","following_url":"https://api.github.com/users/sjl2024/following{/other_user}","gists_url":"https://api.github.com/users/sjl2024/gists{/gist_id}","starred_url":"https://api.github.com/users/sjl2024/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sjl2024/subscriptions","organizations_url":"https://api.github.com/users/sjl2024/orgs","repos_url":"https://api.github.com/users/sjl2024/repos","events_url":"https://api.github.com/users/sjl2024/events{/privacy}","received_events_url":"https://api.github.com/users/sjl2024/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/slimphp/Slim/labels/Type%20-%20Pending%20Feedback","name":"Type - Pending Feedback","color":"DDDDDD"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2014-12-17T04:02:05Z","updated_at":"2015-02-26T00:12:08Z","closed_at":"2015-02-26T00:12:08Z","body":"Hello! Loving Slim framework. However, I found something in the framework which really ought to be classified as a bug and reworked.\r\n\r\nThere are two primary ways one would use the Slim framework. One would be for server-side MVC (using PHP templates), where Slim does all of the view/controller helping. In this instance, a 404 error would refer to an HTTP 404 - Page Not Found status.\r\n\r\nThe second way, which I believe Slim is the perfect framework for, is creating a distributed, stateless REST API. In this case, 404 takes on a different meaning. A 404 from a rest API is indicative that a resource does not exist (I.e. object not found). Moreover, if a URI is not found, a HTTP 400 - Bad Request status would be more appropriate for this.\r\n\r\nUnfortunately, Slim's 'notFound()' handler pigeonholes users into return a HTTP 404 status, due to the halt() call invoked after notFound() executes a callable.\r\n\r\nThis causes two problems:\r\n1) Forced to misuse HTTP404 when using Slim to create a REST API\r\n2) We are forced to use halt() in order to send responses with proper HTTP status codes, which means that we miss out on the slim.after.dispatch hook (as halt invokes stop).\r\n\r\nIn my opinion, the best way to handle this is to simply let the user set the request status in the notFound() handler, and to drop the halt() command. Let this request run out like it normally would, unless a custom notFound callable is never set - in this case, run the default, and then drop the 404 halt.\r\n\r\nRight now, I've simply commented out line 602 of notFound(). This simply allows the OB to get my input like it would on a normal route, and I set the response status myself. However, if you are to patch this, I do believe that the default Slim notFound handler should send a 404 halt! Only skip the halt if a custom handler is set.\r\n\r\nHope this helps,\r\nSam"}}