From a23e5b20aa821345f5934fa4be864eac96b96263 Mon Sep 17 00:00:00 2001 From: DOHA Date: Sun, 15 Feb 2015 12:22:58 +0200 Subject: [PATCH] handle exceptions spring oauth --- .../src/main/java/org/baeldung/web/RedditController.java | 6 +++++- .../src/main/webapp/WEB-INF/jsp/reddit.jsp | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/spring-security-oauth/src/main/java/org/baeldung/web/RedditController.java b/spring-security-oauth/src/main/java/org/baeldung/web/RedditController.java index f973e125b6..4cf73fa098 100644 --- a/spring-security-oauth/src/main/java/org/baeldung/web/RedditController.java +++ b/spring-security-oauth/src/main/java/org/baeldung/web/RedditController.java @@ -1,5 +1,7 @@ package org.baeldung.web; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.security.oauth2.client.OAuth2RestTemplate; import org.springframework.security.oauth2.client.resource.UserApprovalRequiredException; import org.springframework.security.oauth2.client.resource.UserRedirectRequiredException; @@ -12,9 +14,10 @@ import com.fasterxml.jackson.databind.ObjectMapper; @Controller public class RedditController { - private OAuth2RestTemplate redditRestTemplate; + private final Logger LOGGER = LoggerFactory.getLogger(getClass()); + @RequestMapping("/info") public String getInfo(Model model) { try { @@ -27,6 +30,7 @@ public class RedditController { } catch (UserRedirectRequiredException e) { throw e; } catch (Exception e) { + LOGGER.error("Error occurred", e); model.addAttribute("error", e.getLocalizedMessage()); } return "reddit"; diff --git a/spring-security-oauth/src/main/webapp/WEB-INF/jsp/reddit.jsp b/spring-security-oauth/src/main/webapp/WEB-INF/jsp/reddit.jsp index 416a3a6cd2..9ea6cb84fe 100755 --- a/spring-security-oauth/src/main/webapp/WEB-INF/jsp/reddit.jsp +++ b/spring-security-oauth/src/main/webapp/WEB-INF/jsp/reddit.jsp @@ -10,7 +10,11 @@

Your Reddit Info

Your reddit username is ${info} - Sorry, error occurred. + + Sorry, error occurred +

+
${error}
+
\ No newline at end of file