12345678910111213141516171819202122232425262728293031323334 |
- package com.lqkj.cmlcp.exception;
- import com.lqkj.cmlcp.message.Result;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.security.core.userdetails.UsernameNotFoundException;
- import org.springframework.web.bind.annotation.ControllerAdvice;
- import org.springframework.web.bind.annotation.ExceptionHandler;
- import org.springframework.web.bind.annotation.ResponseBody;
- /**
- * 全局异常处理
- */
- @ControllerAdvice
- public class GlobalExceptionHandler {
- private final Logger logger = LoggerFactory.getLogger(this.getClass());
- @ExceptionHandler(Exception.class)
- @ResponseBody
- public Result<String> resolveException(Exception e) {
- logger.error("收到异常", e);
- return Result.fail(e.getMessage());
- }
- @ExceptionHandler(UsernameNotFoundException.class)
- @ResponseBody
- public Result<String> resolveException(UsernameNotFoundException e) {
- logger.error("收到异常", e);
- return Result.fail(e.getMessage());
- }
- }
|