Merge pull request #139 from Doha2012/master
handle exceptions spring oauth
This commit is contained in:
		
						commit
						52e4ea940d
					
				| @ -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"; | ||||
|  | ||||
| @ -10,7 +10,11 @@ | ||||
|         <h1>Your Reddit Info</h1> | ||||
|         <b>Your reddit username is </b>${info} | ||||
|     </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> | ||||
| </body> | ||||
| </html> | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user