Skip to content

Commit a23e5b2

Browse files
committed
handle exceptions spring oauth
1 parent f58831c commit a23e5b2

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

spring-security-oauth/src/main/java/org/baeldung/web/RedditController.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.baeldung.web;
22

3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
35
import org.springframework.security.oauth2.client.OAuth2RestTemplate;
46
import org.springframework.security.oauth2.client.resource.UserApprovalRequiredException;
57
import org.springframework.security.oauth2.client.resource.UserRedirectRequiredException;
@@ -12,9 +14,10 @@
1214

1315
@Controller
1416
public class RedditController {
15-
1617
private OAuth2RestTemplate redditRestTemplate;
1718

19+
private final Logger LOGGER = LoggerFactory.getLogger(getClass());
20+
1821
@RequestMapping("/info")
1922
public String getInfo(Model model) {
2023
try {
@@ -27,6 +30,7 @@ public String getInfo(Model model) {
2730
} catch (UserRedirectRequiredException e) {
2831
throw e;
2932
} catch (Exception e) {
33+
LOGGER.error("Error occurred", e);
3034
model.addAttribute("error", e.getLocalizedMessage());
3135
}
3236
return "reddit";

spring-security-oauth/src/main/webapp/WEB-INF/jsp/reddit.jsp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
<h1>Your Reddit Info</h1>
1111
<b>Your reddit username is </b>${info}
1212
</c:when>
13-
<c:otherwise> Sorry, error occurred.</c:otherwise>
13+
<c:otherwise>
14+
<b>Sorry, error occurred</b>
15+
<br><br>
16+
<div>${error}</div>
17+
</c:otherwise>
1418
</c:choose>
1519
</body>
1620
</html>

0 commit comments

Comments
 (0)