{"action":"opened","issue":{"url":"https://api.github.com/repos/spring-projects/spring-security-oauth/issues/387","labels_url":"https://api.github.com/repos/spring-projects/spring-security-oauth/issues/387/labels{/name}","comments_url":"https://api.github.com/repos/spring-projects/spring-security-oauth/issues/387/comments","events_url":"https://api.github.com/repos/spring-projects/spring-security-oauth/issues/387/events","html_url":"https://github.com/spring-projects/spring-security-oauth/issues/387","id":56602174,"number":387,"title":"OAuth2RestTemplate never delegates to custom error handlers","user":{"login":"mressler","id":605015,"avatar_url":"https://avatars.githubusercontent.com/u/605015?v=3","gravatar_id":"","url":"https://api.github.com/users/mressler","html_url":"https://github.com/mressler","followers_url":"https://api.github.com/users/mressler/followers","following_url":"https://api.github.com/users/mressler/following{/other_user}","gists_url":"https://api.github.com/users/mressler/gists{/gist_id}","starred_url":"https://api.github.com/users/mressler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mressler/subscriptions","organizations_url":"https://api.github.com/users/mressler/orgs","repos_url":"https://api.github.com/users/mressler/repos","events_url":"https://api.github.com/users/mressler/events{/privacy}","received_events_url":"https://api.github.com/users/mressler/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-02-04T23:08:42Z","updated_at":"2015-02-04T23:08:42Z","closed_at":null,"body":"While testing my Spring OAuth2 implementation (thank you!) I noticed that if my server returned a 403 Forbidden, my `OAuth2RestTemplate` would only ever throw `OAuth2Exceptions` instead of the expected `HttpClientErrorException`.  Further, the custom error handler that I had set up was never being called.\r\n\r\nIt looks like the `setErrorHandler` call in the `OAuth2RestTemplate` wraps my error custom error handler in an `OAuth2ErrorHandler`.  By itself, this is fine and I'm glad that there are standard errors that can be sniffed out and handled in this way.  My problem is on line 127 of `OAuth2ErrorHandler`:https://github.com/spring-projects/spring-security-oauth/blob/master/spring-security-oauth2/src/main/java/org/springframework/security/oauth2/client/http/OAuth2ErrorHandler.java#L127\r\n\r\n```\r\nOAuth2Exception body = extractor.extractData(bufferedResponse);\r\nif (body != null) {\r\n```\r\n\r\nLooking at the `OAuth2ExceptionJackson2Deserializer`, it looks like line 127 will always return a non-null body object.  In my particular case, I'm returning my own custom JSON error content for the 403 result, but I'm still getting the `OAuth2Exception` deserialized from that line 127.  And, since the body object is non-null, the error handler never delegates to my custom error handler (line 148).\r\n\r\nIt seems like line 128 should be doing something a little more specific than just making sure it's non-null.  In my case, the resulting JSON was not intended to be turned into an `OAuth2Exception`.  Shouldn't line 128 looks for a return value that is a subclass of OAuth2Exception?\r\n"}}