{"action":"created","issue":{"url":"https://api.github.com/repos/plone/plone.rest/issues/19","labels_url":"https://api.github.com/repos/plone/plone.rest/issues/19/labels{/name}","comments_url":"https://api.github.com/repos/plone/plone.rest/issues/19/comments","events_url":"https://api.github.com/repos/plone/plone.rest/issues/19/events","html_url":"https://github.com/plone/plone.rest/pull/19","id":117853711,"number":19,"title":"implement standard error handling.","user":{"login":"jone","id":7469,"avatar_url":"https://avatars.githubusercontent.com/u/7469?v=3","gravatar_id":"","url":"https://api.github.com/users/jone","html_url":"https://github.com/jone","followers_url":"https://api.github.com/users/jone/followers","following_url":"https://api.github.com/users/jone/following{/other_user}","gists_url":"https://api.github.com/users/jone/gists{/gist_id}","starred_url":"https://api.github.com/users/jone/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jone/subscriptions","organizations_url":"https://api.github.com/users/jone/orgs","repos_url":"https://api.github.com/users/jone/repos","events_url":"https://api.github.com/users/jone/events{/privacy}","received_events_url":"https://api.github.com/users/jone/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/plone/plone.rest/labels/pr%20ready","name":"pr ready","color":"009800"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":14,"created_at":"2015-11-19T16:39:51Z","updated_at":"2015-11-24T08:38:35Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/plone/plone.rest/pulls/19","html_url":"https://github.com/plone/plone.rest/pull/19","diff_url":"https://github.com/plone/plone.rest/pull/19.diff","patch_url":"https://github.com/plone/plone.rest/pull/19.patch"},"body":":grey_exclamation: base and target branch is `error-handling`  for inclusion in #13 :grey_exclamation: \r\n\r\nI've started implementing JSON error handling by providing an `index.html` adapter for exceptions.\r\nThis works quite well, but not for `Unauthorized` exceptions.\r\n\r\n**1) Unauthorized is tricky**\r\nThe unauthorized exception is the only exception which is re-raised ([here](https://github.com/zopefoundation/Zope/blob/2.13.23/src/Zope2/App/startup.py#L231-L236)).\r\nThe exception is handled different than any other exceptions: mainly the PAS is asked and it leads to a redirect to the `login_form`.\r\nI can suppress the redirect, but I'm unable to render non-HTML response since I'm not in control of that anymore.\r\n\r\nMy approach for fixing that is below, but it does not work, it only prevents redirecting:\r\n```python\r\n        if isinstance(exception, Unauthorized):\r\n            response.setStatus(type(exception))\r\n            response.setBody(result)\r\n            # Avoid redirect to login page on 404s by adding challenged flag\r\n            response._has_challenged = True\r\n            return\r\n```\r\n\r\n**2. Show exception to non-privileged users?**\r\nIn non-api Plone, the exception details are only rendered to privileged users. Anonymous / unprivileged users only get an \"An error occured\" and an error number.\r\nHow do we want to handle that in the API?\r\n(I did not yet implement anything).\r\n\r\n/cc @tisto @bloodbare @lukasgraf @buchi "},"comment":{"url":"https://api.github.com/repos/plone/plone.rest/issues/comments/159195957","html_url":"https://github.com/plone/plone.rest/pull/19#issuecomment-159195957","issue_url":"https://api.github.com/repos/plone/plone.rest/issues/19","id":159195957,"user":{"login":"lukasgraf","id":405124,"avatar_url":"https://avatars.githubusercontent.com/u/405124?v=3","gravatar_id":"","url":"https://api.github.com/users/lukasgraf","html_url":"https://github.com/lukasgraf","followers_url":"https://api.github.com/users/lukasgraf/followers","following_url":"https://api.github.com/users/lukasgraf/following{/other_user}","gists_url":"https://api.github.com/users/lukasgraf/gists{/gist_id}","starred_url":"https://api.github.com/users/lukasgraf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lukasgraf/subscriptions","organizations_url":"https://api.github.com/users/lukasgraf/orgs","repos_url":"https://api.github.com/users/lukasgraf/repos","events_url":"https://api.github.com/users/lukasgraf/events{/privacy}","received_events_url":"https://api.github.com/users/lukasgraf/received_events","type":"User","site_admin":false},"created_at":"2015-11-24T08:38:35Z","updated_at":"2015-11-24T08:38:35Z","body":":+1: "}}