{"action":"created","issue":{"url":"https://api.github.com/repos/alphagov/publishing-api/issues/123","labels_url":"https://api.github.com/repos/alphagov/publishing-api/issues/123/labels{/name}","comments_url":"https://api.github.com/repos/alphagov/publishing-api/issues/123/comments","events_url":"https://api.github.com/repos/alphagov/publishing-api/issues/123/events","html_url":"https://github.com/alphagov/publishing-api/pull/123","id":115330240,"number":123,"title":"Force text error template when exceptions occur","user":{"login":"tijmenb","id":233676,"avatar_url":"https://avatars.githubusercontent.com/u/233676?v=3","gravatar_id":"","url":"https://api.github.com/users/tijmenb","html_url":"https://github.com/tijmenb","followers_url":"https://api.github.com/users/tijmenb/followers","following_url":"https://api.github.com/users/tijmenb/following{/other_user}","gists_url":"https://api.github.com/users/tijmenb/gists{/gist_id}","starred_url":"https://api.github.com/users/tijmenb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tijmenb/subscriptions","organizations_url":"https://api.github.com/users/tijmenb/orgs","repos_url":"https://api.github.com/users/tijmenb/repos","events_url":"https://api.github.com/users/tijmenb/events{/privacy}","received_events_url":"https://api.github.com/users/tijmenb/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-11-05T17:10:42Z","updated_at":"2015-11-09T15:24:01Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/alphagov/publishing-api/pulls/123","html_url":"https://github.com/alphagov/publishing-api/pull/123","diff_url":"https://github.com/alphagov/publishing-api/pull/123.diff","patch_url":"https://github.com/alphagov/publishing-api/pull/123.patch"},"body":"Rails by default shows nice error pages, with a lot of markup, css and javascript. This is cool when you visit the page in the browser, but not helpful when you consume the app as an API. Rails' HTML response then makes it really hard find the error when it's displayed as part of the exception message.\r\n\r\nBut Rails will [render a text-based exception](https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb#L93-L99) when doing AJAX requests. By setting the `X-Requested-With` header we can make Rails show the text template for all requests.\r\n\r\nNote that there's still some markup in the error. This is a Rails bug, addressed in https://github.com/rails/rails/pull/22172.\r\n\r\nThis is the result saving something in Panopticon that triggers an exception in publishing-api (in this case because I hadn't run the migrations). \r\n\r\n## Before\r\n\r\n![screen shot 2015-11-05 at 14 34 27](https://cloud.githubusercontent.com/assets/233676/10975602/b76e80a0-83df-11e5-8bee-9b82cf84a613.png)\r\n(and much more scrolling)\r\n\r\n## After\r\n\r\n![screen shot 2015-11-05 at 14 36 27](https://cloud.githubusercontent.com/assets/233676/10975603/b7732588-83df-11e5-8807-7d5be65b75cc.png)\r\n\r\nI feel this is not a great solution. I'm considering a PR on Rails to show the text-template for all non-HTML requests, or make it configurable.\r\n"},"comment":{"url":"https://api.github.com/repos/alphagov/publishing-api/issues/comments/155094684","html_url":"https://github.com/alphagov/publishing-api/pull/123#issuecomment-155094684","issue_url":"https://api.github.com/repos/alphagov/publishing-api/issues/123","id":155094684,"user":{"login":"AndrewVos","id":363618,"avatar_url":"https://avatars.githubusercontent.com/u/363618?v=3","gravatar_id":"","url":"https://api.github.com/users/AndrewVos","html_url":"https://github.com/AndrewVos","followers_url":"https://api.github.com/users/AndrewVos/followers","following_url":"https://api.github.com/users/AndrewVos/following{/other_user}","gists_url":"https://api.github.com/users/AndrewVos/gists{/gist_id}","starred_url":"https://api.github.com/users/AndrewVos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndrewVos/subscriptions","organizations_url":"https://api.github.com/users/AndrewVos/orgs","repos_url":"https://api.github.com/users/AndrewVos/repos","events_url":"https://api.github.com/users/AndrewVos/events{/privacy}","received_events_url":"https://api.github.com/users/AndrewVos/received_events","type":"User","site_admin":false},"created_at":"2015-11-09T15:24:01Z","updated_at":"2015-11-09T15:24:01Z","body":"lgtm!"}}