{"action":"created","issue":{"url":"https://api.github.com/repos/spring-projects/spring-security-oauth/issues/610","repository_url":"https://api.github.com/repos/spring-projects/spring-security-oauth","labels_url":"https://api.github.com/repos/spring-projects/spring-security-oauth/issues/610/labels{/name}","comments_url":"https://api.github.com/repos/spring-projects/spring-security-oauth/issues/610/comments","events_url":"https://api.github.com/repos/spring-projects/spring-security-oauth/issues/610/events","html_url":"https://github.com/spring-projects/spring-security-oauth/issues/610","id":113341220,"number":610,"title":"How to customize my own exception handler in token endpoint?","user":{"login":"jzbjyb","id":5134761,"avatar_url":"https://avatars0.githubusercontent.com/u/5134761?v=3","gravatar_id":"","url":"https://api.github.com/users/jzbjyb","html_url":"https://github.com/jzbjyb","followers_url":"https://api.github.com/users/jzbjyb/followers","following_url":"https://api.github.com/users/jzbjyb/following{/other_user}","gists_url":"https://api.github.com/users/jzbjyb/gists{/gist_id}","starred_url":"https://api.github.com/users/jzbjyb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jzbjyb/subscriptions","organizations_url":"https://api.github.com/users/jzbjyb/orgs","repos_url":"https://api.github.com/users/jzbjyb/repos","events_url":"https://api.github.com/users/jzbjyb/events{/privacy}","received_events_url":"https://api.github.com/users/jzbjyb/received_events","type":"User","site_admin":false},"labels":[{"id":88382379,"url":"https://api.github.com/repos/spring-projects/spring-security-oauth/labels/Question","name":"Question","color":"eb6420","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":15,"created_at":"2015-10-26T12:04:14Z","updated_at":"2017-04-26T10:17:58Z","closed_at":"2015-12-07T10:41:22Z","body":"The exceptions thrown in each endpoint are caught by @ExceptionHandler methods in the same class. What i want to do is to catch these exceptions (such as OAuth2Exception, InvalidTokenException) in my @ExceptionHandler and then customize the output.\n\nThe raw exception output is something like {\"error\": \"...\", \"error_description\": \"...\"} which is not what i want. I expect the output to be {\"code\": 400, \"message\": \"...\"}.\n"},"comment":{"url":"https://api.github.com/repos/spring-projects/spring-security-oauth/issues/comments/297337038","html_url":"https://github.com/spring-projects/spring-security-oauth/issues/610#issuecomment-297337038","issue_url":"https://api.github.com/repos/spring-projects/spring-security-oauth/issues/610","id":297337038,"user":{"login":"stefli","id":56305,"avatar_url":"https://avatars0.githubusercontent.com/u/56305?v=3","gravatar_id":"","url":"https://api.github.com/users/stefli","html_url":"https://github.com/stefli","followers_url":"https://api.github.com/users/stefli/followers","following_url":"https://api.github.com/users/stefli/following{/other_user}","gists_url":"https://api.github.com/users/stefli/gists{/gist_id}","starred_url":"https://api.github.com/users/stefli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stefli/subscriptions","organizations_url":"https://api.github.com/users/stefli/orgs","repos_url":"https://api.github.com/users/stefli/repos","events_url":"https://api.github.com/users/stefli/events{/privacy}","received_events_url":"https://api.github.com/users/stefli/received_events","type":"User","site_admin":false},"created_at":"2017-04-26T10:17:58Z","updated_at":"2017-04-26T10:17:58Z","body":"@hassalih you can rewrite the DefaultOAuth2ExceptionRenderer and change the output with your format. Just change the \r\n`OAuth2Exception exception = (OAuth2Exception) responseEntity.getBody();\r\n        CustomResponse<Object> response = new CustomResponse<Object>(exception.getOAuth2ErrorCode(),\r\n                exception.getLocalizedMessage()); // You can define your own response format here.\r\n        if (response != null) {\r\n            writeWithMessageConverters(response, inputMessage, outputMessage);\r\n       }`\r\n\r\nAfter rewrite, you need to register it to \r\n<bean id=\"oauthAuthenticationEntryPoint\"\r\n\t\tclass=\"org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint\"\r\n\t\tp:exceptionRenderer-ref=\"**exceptionRenderer**\" />\r\n\r\nThen the output is pretty well as what you want."}}
{"actor":{"display_login":"stefli"}}