CustomWebResponseExceptionTranslator.java 746 B

123456789101112131415161718192021
  1. package com.ruoyi.auth.exception;
  2. import javax.servlet.http.HttpServletResponse;
  3. import org.springframework.http.ResponseEntity;
  4. import org.springframework.security.oauth2.common.exceptions.OAuth2Exception;
  5. import org.springframework.security.oauth2.provider.error.WebResponseExceptionTranslator;
  6. /**
  7. * OAuth2 自定义异常处理
  8. *
  9. * @author ruoyi
  10. */
  11. public class CustomWebResponseExceptionTranslator implements WebResponseExceptionTranslator<OAuth2Exception>
  12. {
  13. @Override
  14. public ResponseEntity<OAuth2Exception> translate(Exception e)
  15. {
  16. OAuth2Exception oAuth2Exception = (OAuth2Exception) e;
  17. return ResponseEntity.status(HttpServletResponse.SC_UNAUTHORIZED).body(oAuth2Exception);
  18. }
  19. }