ExceptionAdvice.java 1009 B

1234567891011121314151617181920212223242526272829
  1. package com.mooctest.crowd.domain.controller.advice;
  2. import com.mooctest.crowd.domain.constants.ResponseConstant;
  3. import com.mooctest.crowd.domain.data.ResponseMessage;
  4. import com.mooctest.crowd.domain.exception.AccountNotExistException;
  5. import com.mooctest.crowd.domain.exception.BaseException;
  6. import org.springframework.http.HttpStatus;
  7. import org.springframework.web.bind.annotation.ExceptionHandler;
  8. import org.springframework.web.bind.annotation.ResponseStatus;
  9. import org.springframework.web.bind.annotation.RestControllerAdvice;
  10. /**
  11. * @author: Diors.Po
  12. * @Email: 171256175@qq.com
  13. * @date 2019-07-25 00:08
  14. */
  15. @RestControllerAdvice
  16. public class ExceptionAdvice {
  17. @ExceptionHandler(BaseException.class)
  18. @ResponseStatus(HttpStatus.BAD_REQUEST)
  19. public ResponseMessage handleException(Exception e){
  20. if (e instanceof AccountNotExistException){
  21. return new ResponseMessage(ResponseConstant.FAIL, ResponseConstant.USER_NOT_EXISTS);
  22. }
  23. return null;
  24. }
  25. }