{"action":"created","issue":{"url":"https://api.github.com/repos/gonzalo-bulnes/simple_token_authentication/issues/201","labels_url":"https://api.github.com/repos/gonzalo-bulnes/simple_token_authentication/issues/201/labels{/name}","comments_url":"https://api.github.com/repos/gonzalo-bulnes/simple_token_authentication/issues/201/comments","events_url":"https://api.github.com/repos/gonzalo-bulnes/simple_token_authentication/issues/201/events","html_url":"https://github.com/gonzalo-bulnes/simple_token_authentication/issues/201","id":116944637,"number":201,"title":"fallback: :exception with JSON returns empty error message","user":{"login":"iampeter","id":713801,"avatar_url":"https://avatars.githubusercontent.com/u/713801?v=3","gravatar_id":"","url":"https://api.github.com/users/iampeter","html_url":"https://github.com/iampeter","followers_url":"https://api.github.com/users/iampeter/followers","following_url":"https://api.github.com/users/iampeter/following{/other_user}","gists_url":"https://api.github.com/users/iampeter/gists{/gist_id}","starred_url":"https://api.github.com/users/iampeter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iampeter/subscriptions","organizations_url":"https://api.github.com/users/iampeter/orgs","repos_url":"https://api.github.com/users/iampeter/repos","events_url":"https://api.github.com/users/iampeter/events{/privacy}","received_events_url":"https://api.github.com/users/iampeter/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/gonzalo-bulnes/simple_token_authentication/labels/question","name":"question","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-11-14T18:50:48Z","updated_at":"2016-01-28T10:28:48Z","closed_at":null,"body":"I am forcing JSON response and using `fallback: :exception`, and the response is \r\n\r\n```\r\n{\r\n\"error\": \"\"\r\n}\r\n```\r\n\r\nalthough the code in `ExceptionCallbackHandler` says\r\n```\r\nthrow(:warden, scope: entity.name_underscore.to_sym) if controller.send(\"current_#{entity.name_underscore}\").nil?\r\n```\r\n\r\nWhy doesn't it return any message?\r\n\r\nI have tried doing it this way:\r\n```\r\n  class UnauthenticatedException < Exception\r\n  end\r\n\r\n  rescue_from UnauthenticatedException do |exception|\r\n    render json: { error: \"Authentication error\", code: 1 }, status: 401\r\n  end\r\n\r\n  class ApiExceptionFallbackHandler\r\n    # Notifies the failure of authentication to Warden in the same DEvise does.\r\n    # Does result in an HTTP 401 response in a Devise context.\r\n    def fallback!(controller, entity)\r\n      raise UnauthenticatedException.new if controller.send(\"current_#{entity.name_underscore}\").nil?\r\n    end\r\n  end\r\n\r\n  @@fallback_authentication_handler = ApiExceptionFallbackHandler.new\r\n\r\n  acts_as_token_authentication_handler_for ApiKey\r\n```\r\n\r\nand it works, but am bot sure if raising and Exception instead of throw(:warden) is a legitimate way here.\r\n"},"comment":{"url":"https://api.github.com/repos/gonzalo-bulnes/simple_token_authentication/issues/comments/176112302","html_url":"https://github.com/gonzalo-bulnes/simple_token_authentication/issues/201#issuecomment-176112302","issue_url":"https://api.github.com/repos/gonzalo-bulnes/simple_token_authentication/issues/201","id":176112302,"user":{"login":"iampeter","id":713801,"avatar_url":"https://avatars.githubusercontent.com/u/713801?v=3","gravatar_id":"","url":"https://api.github.com/users/iampeter","html_url":"https://github.com/iampeter","followers_url":"https://api.github.com/users/iampeter/followers","following_url":"https://api.github.com/users/iampeter/following{/other_user}","gists_url":"https://api.github.com/users/iampeter/gists{/gist_id}","starred_url":"https://api.github.com/users/iampeter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iampeter/subscriptions","organizations_url":"https://api.github.com/users/iampeter/orgs","repos_url":"https://api.github.com/users/iampeter/repos","events_url":"https://api.github.com/users/iampeter/events{/privacy}","received_events_url":"https://api.github.com/users/iampeter/received_events","type":"User","site_admin":false},"created_at":"2016-01-28T10:28:48Z","updated_at":"2016-01-28T10:28:48Z","body":"@gonzalo-bulnes nope. that's why I'm doing it like mentioned in my original comment"}}