Merge pull request #163 from Doha2012/master

Fix access token problem
This commit is contained in:
Eugen 2015-03-11 17:45:55 +02:00
commit 29fb3263c9
2 changed files with 18 additions and 9 deletions

View File

@ -223,6 +223,8 @@ public class RedditController {
} else {
user.setNeedCaptcha(false);
}
user.setAccessToken(token.getValue());
user.setRefreshToken(token.getRefreshToken().getValue());
userReopsitory.save(user);
}

View File

@ -4,8 +4,6 @@ import java.io.Serializable;
import javax.servlet.http.HttpServletResponse;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.oauth2.client.resource.OAuth2AccessDeniedException;
import org.springframework.security.oauth2.client.resource.UserApprovalRequiredException;
@ -14,6 +12,7 @@ import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
@ControllerAdvice
@ -30,17 +29,23 @@ public class RestExceptionHandler extends ResponseEntityExceptionHandler impleme
// 4xx
@ExceptionHandler({ OAuth2AccessDeniedException.class })
public ResponseEntity<Object> handleOAuth2AccessDeniedException(final OAuth2AccessDeniedException ex, final WebRequest request) {
public ModelAndView handleOAuth2AccessDeniedException(final OAuth2AccessDeniedException ex, final WebRequest request) {
logger.error("403 Status Code", ex);
final String response = "Error Occurred - Forbidden: " + ex.getMessage();
return handleExceptionInternal(ex, response, new HttpHeaders(), HttpStatus.FORBIDDEN, request);
final ModelAndView model = new ModelAndView("submissionResponse");
model.addObject("msg", response);
return model;
// return handleExceptionInternal(ex, response, new HttpHeaders(), HttpStatus.FORBIDDEN, request);
}
@ExceptionHandler({ HttpClientErrorException.class })
public ResponseEntity<Object> handleHttpClientErrorException(final HttpClientErrorException ex, final WebRequest request) {
public ModelAndView handleHttpClientErrorException(final HttpClientErrorException ex, final WebRequest request) {
logger.error("400 Status Code", ex);
final String response = "Error Occurred - To Many Requests: " + ex.getMessage();
return handleExceptionInternal(ex, response, new HttpHeaders(), HttpStatus.TOO_MANY_REQUESTS, request);
final ModelAndView model = new ModelAndView("submissionResponse");
model.addObject("msg", response);
return model;
// return handleExceptionInternal(ex, response, new HttpHeaders(), HttpStatus.TOO_MANY_REQUESTS, request);
}
// HttpClientErrorException
@ -53,10 +58,12 @@ public class RestExceptionHandler extends ResponseEntityExceptionHandler impleme
}
@ExceptionHandler({ Exception.class })
public ResponseEntity<Object> handleInternal(final RuntimeException ex, final WebRequest request, final HttpServletResponse response) {
public ModelAndView handleInternal(final RuntimeException ex, final WebRequest request, final HttpServletResponse response) {
logger.info(response.getHeader("x-ratelimit-remaining"));
logger.error("500 Status Code", ex);
final String message = "Error Occurred: " + ex.getMessage();
return handleExceptionInternal(ex, message, new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR, request);
final String message = "Error Occurred: " + ex.getLocalizedMessage();
final ModelAndView model = new ModelAndView("submissionResponse");
model.addObject("msg", message);
return model;
}
}