ExceptionAspect.java 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package com.edu.service.aspect;
  2. import com.edu.service.exception.BussinessException;
  3. import com.edu.service.exception.SystemException;
  4. import com.edu.base.ResponseEntity;
  5. import com.meitong.framework.constant.Constants;
  6. import org.apache.logging.log4j.LogManager;
  7. import org.apache.logging.log4j.Logger;
  8. import org.aspectj.lang.ProceedingJoinPoint;
  9. /**
  10. * @author wu youyang
  11. */
  12. public class ExceptionAspect
  13. {
  14. private Logger logger = LogManager.getLogger(this.getClass());
  15. private String systemCode;
  16. public void setSystemCode(String systemCode) {
  17. this.systemCode = systemCode;
  18. }
  19. /**
  20. * 处理运行异常的切面
  21. * */
  22. public Object deal(ProceedingJoinPoint pjp) throws Throwable {
  23. Object returnMessage = null;
  24. Class<?> aClass = pjp.getTarget().getClass();
  25. // logger.info(aClass.getName() + "#" + pjp.getSignature().getName() + ": request:{}", pjp.getArgs());
  26. try {
  27. returnMessage = pjp.proceed();
  28. } catch (BussinessException e0) {
  29. logger.error("",e0);
  30. returnMessage = new ResponseEntity(e0.getErrCode(), e0.getMessage());
  31. } catch (IllegalArgumentException e1) {
  32. logger.error("",e1);
  33. returnMessage = new ResponseEntity(this.systemCode + Constants.SYS_ERROR_CODE05, Constants.SYS_ERROR_MSG05 + e1.getMessage());
  34. }catch (SystemException e2) {
  35. logger.error("",e2);
  36. returnMessage = new ResponseEntity(this.systemCode + Constants.SYS_ERROR_CODE05, Constants.SYS_ERROR_MSG05);
  37. } catch (Exception e3) {
  38. logger.error("",e3);
  39. returnMessage = new ResponseEntity(this.systemCode + Constants.RUN_TIME_ERROR_CODE, Constants.RUN_TIME_ERROR_MSG + e3.getMessage());
  40. }
  41. // logger.info(aClass.getName() + "#" + pjp.getSignature().getName() + ": response:{}", returnMessage);
  42. return returnMessage;
  43. }
  44. }