ServiceException.java 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package cn.iocoder.dashboard.common.exception;
  2. import cn.iocoder.dashboard.common.exception.enums.ServiceErrorCodeRange;
  3. import lombok.Data;
  4. import lombok.EqualsAndHashCode;
  5. /**
  6. * 业务逻辑异常 Exception
  7. */
  8. @Data
  9. @EqualsAndHashCode(callSuper = true)
  10. public final class ServiceException extends RuntimeException {
  11. /**
  12. * 业务错误码
  13. *
  14. * @see ServiceErrorCodeRange
  15. */
  16. private Integer code;
  17. /**
  18. * 错误提示
  19. */
  20. private String message;
  21. /**
  22. * 空构造方法,避免反序列化问题
  23. */
  24. public ServiceException() {
  25. }
  26. public ServiceException(ErrorCode errorCode) {
  27. this.code = errorCode.getCode();
  28. this.message = errorCode.getMsg();
  29. }
  30. public ServiceException(Integer code, String message) {
  31. this.code = code;
  32. this.message = message;
  33. }
  34. public Integer getCode() {
  35. return code;
  36. }
  37. public ServiceException setCode(Integer code) {
  38. this.code = code;
  39. return this;
  40. }
  41. @Override
  42. public String getMessage() {
  43. return message;
  44. }
  45. public ServiceException setMessage(String message) {
  46. this.message = message;
  47. return this;
  48. }
  49. }