{"action":"created","issue":{"url":"https://api.github.com/repos/Luracast/Restler/issues/421","labels_url":"https://api.github.com/repos/Luracast/Restler/issues/421/labels{/name}","comments_url":"https://api.github.com/repos/Luracast/Restler/issues/421/comments","events_url":"https://api.github.com/repos/Luracast/Restler/issues/421/events","html_url":"https://github.com/Luracast/Restler/issues/421","id":61029170,"number":421,"title":"Hybrid authentication and bad credentials","user":{"login":"HomelessGruesomeMoose","id":1420144,"avatar_url":"https://avatars.githubusercontent.com/u/1420144?v=3","gravatar_id":"","url":"https://api.github.com/users/HomelessGruesomeMoose","html_url":"https://github.com/HomelessGruesomeMoose","followers_url":"https://api.github.com/users/HomelessGruesomeMoose/followers","following_url":"https://api.github.com/users/HomelessGruesomeMoose/following{/other_user}","gists_url":"https://api.github.com/users/HomelessGruesomeMoose/gists{/gist_id}","starred_url":"https://api.github.com/users/HomelessGruesomeMoose/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HomelessGruesomeMoose/subscriptions","organizations_url":"https://api.github.com/users/HomelessGruesomeMoose/orgs","repos_url":"https://api.github.com/users/HomelessGruesomeMoose/repos","events_url":"https://api.github.com/users/HomelessGruesomeMoose/events{/privacy}","received_events_url":"https://api.github.com/users/HomelessGruesomeMoose/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-03-13T10:14:37Z","updated_at":"2015-03-16T13:21:10Z","closed_at":"2015-03-16T13:21:10Z","body":"Hi,\r\n\r\nI'm facing with an issue with hybrid authentication. I want my resource to be partially publicly available but I also want to tell the client when their credentials are in invalid.\r\n\r\nAt the moment, if the client gives bad credentials, I throw a RestException which seems to be caught somewhere in Restler and the client gets the version of the resource which is   publicly available.\r\nThus, I tried throwing a custom Exception for bad credentials. Unfortunately, Restler will transform this into a 500 Error when it should be 401 and I can't choose the message.\r\n\r\nI did find a partial workaround:\r\n\r\n```php\r\n$restler->addErrorClass('InvalidBasicAuthentcationException');\r\n\r\nclass InvalidBasicAuthentcationException extends \\Exception {\r\n\r\n   public function handle500() {\r\n       throw new RestException(401, 'Invalid Basic Authentication Credentials');\r\n   }\r\n}\r\n```\r\n\r\nHowever, the problem is that now all 500 Exceptions are transformed into 401.\r\n\r\nA quick hack will be to do this in Restler.class.php (1096):\r\n\r\n```\r\nif (!$exception instanceof RestException) {\r\n           $exception = new RestException(\r\n---                    500,\r\n+++                ($exception->getCode()) ? $exception->getCode() : 500,\r\n               $this->productionMode ? null : $exception->getMessage(),\r\n               array(),\r\n               $exception\r\n           );\r\n       }\r\n```\r\n\r\nWhich would allow me to throw an exception with some crazy number, say 9999, to be handled specifically.\r\n\r\nWould you have any other suggestions?\r\nThanks"},"comment":{"url":"https://api.github.com/repos/Luracast/Restler/issues/comments/81661338","html_url":"https://github.com/Luracast/Restler/issues/421#issuecomment-81661338","issue_url":"https://api.github.com/repos/Luracast/Restler/issues/421","id":81661338,"user":{"login":"Arul-","id":2255137,"avatar_url":"https://avatars.githubusercontent.com/u/2255137?v=3","gravatar_id":"","url":"https://api.github.com/users/Arul-","html_url":"https://github.com/Arul-","followers_url":"https://api.github.com/users/Arul-/followers","following_url":"https://api.github.com/users/Arul-/following{/other_user}","gists_url":"https://api.github.com/users/Arul-/gists{/gist_id}","starred_url":"https://api.github.com/users/Arul-/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Arul-/subscriptions","organizations_url":"https://api.github.com/users/Arul-/orgs","repos_url":"https://api.github.com/users/Arul-/repos","events_url":"https://api.github.com/users/Arul-/events{/privacy}","received_events_url":"https://api.github.com/users/Arul-/received_events","type":"User","site_admin":false},"created_at":"2015-03-16T13:21:10Z","updated_at":"2015-03-16T13:21:10Z","body":"Solution is simple, you just have to keep `RestException` as your base class instead of `Exception`\r\n\r\n"}}