Merge pull request #139 from Doha2012/master

handle exceptions spring oauth
This commit is contained in:
Eugen 2015-02-15 12:48:31 +02:00
commit 52e4ea940d
2 changed files with 10 additions and 2 deletions

View File

@ -1,5 +1,7 @@
package org.baeldung.web; 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.OAuth2RestTemplate;
import org.springframework.security.oauth2.client.resource.UserApprovalRequiredException; import org.springframework.security.oauth2.client.resource.UserApprovalRequiredException;
import org.springframework.security.oauth2.client.resource.UserRedirectRequiredException; import org.springframework.security.oauth2.client.resource.UserRedirectRequiredException;
@ -12,9 +14,10 @@ import com.fasterxml.jackson.databind.ObjectMapper;
@Controller @Controller
public class RedditController { public class RedditController {
private OAuth2RestTemplate redditRestTemplate; private OAuth2RestTemplate redditRestTemplate;
private final Logger LOGGER = LoggerFactory.getLogger(getClass());
@RequestMapping("/info") @RequestMapping("/info")
public String getInfo(Model model) { public String getInfo(Model model) {
try { try {
@ -27,6 +30,7 @@ public class RedditController {
} catch (UserRedirectRequiredException e) { } catch (UserRedirectRequiredException e) {
throw e; throw e;
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("Error occurred", e);
model.addAttribute("error", e.getLocalizedMessage()); model.addAttribute("error", e.getLocalizedMessage());
} }
return "reddit"; return "reddit";

View File

@ -10,7 +10,11 @@
<h1>Your Reddit Info</h1> <h1>Your Reddit Info</h1>
<b>Your reddit username is </b>${info} <b>Your reddit username is </b>${info}
</c:when> </c:when>
<c:otherwise> Sorry, error occurred.</c:otherwise> <c:otherwise>
<b>Sorry, error occurred</b>
<br><br>
<div>${error}</div>
</c:otherwise>
</c:choose> </c:choose>
</body> </body>
</html> </html>