BusinessException.java 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. package com.persagy.common.exception;
  2. import com.persagy.common.enums.ResponseCode;
  3. /**
  4. * @description
  5. * @author zhangqiankun
  6. * @since 2020年8月26日: 下午5:17:08
  7. */
  8. public class BusinessException extends RuntimeException {
  9. private static final long serialVersionUID = -3325873096967595156L;
  10. private String errorCode;
  11. private String errorDesc; // 给前端看
  12. private Object respJson; // 响应content中的数据,可加可不加
  13. public BusinessException() {
  14. super();
  15. }
  16. public BusinessException(Throwable e) {
  17. super(e);
  18. }
  19. public BusinessException(String message, Throwable e) {
  20. super(message, e);
  21. }
  22. /**
  23. * @param errorCode 默认 B0001
  24. * @param errorDesc
  25. */
  26. public BusinessException(String errorDesc) {
  27. super(errorDesc);
  28. this.errorCode = ResponseCode.B0001.getCode();
  29. this.errorDesc = errorDesc;
  30. }
  31. /**
  32. * 业务异常错误码和错误描述构造器
  33. *
  34. * @param errorCode
  35. * @param errorDesc
  36. */
  37. public BusinessException(String errorCode, String errorDesc) {
  38. super(errorDesc);
  39. this.errorCode = errorCode;
  40. this.errorDesc = errorDesc;
  41. }
  42. public BusinessException(String errorCode, String errorDesc, Object respJson) {
  43. super(errorDesc);
  44. this.errorCode = errorCode;
  45. this.errorDesc = errorDesc;
  46. this.respJson = respJson;
  47. }
  48. /**
  49. * 业务异常信息、错误码和错误描述构造器
  50. *
  51. * @param message 后台日志看
  52. * @param errorCode 错误码
  53. * @param errorDesc 给前端看
  54. */
  55. public BusinessException(String message, String errorCode, String errorDesc, Object respJson) {
  56. super(message);
  57. this.errorCode = errorCode;
  58. this.errorDesc = errorDesc;
  59. this.respJson = respJson;
  60. }
  61. public BusinessException(Throwable cause, String errorCode, String errorDesc) {
  62. super(cause);
  63. this.errorCode = errorCode;
  64. this.errorDesc = errorDesc;
  65. }
  66. public BusinessException(String message, Throwable cause, String errorCode, String errorDesc) {
  67. super(message, cause);
  68. this.errorCode = errorCode;
  69. this.errorDesc = errorDesc;
  70. }
  71. public String getErrorCode() {
  72. return errorCode;
  73. }
  74. public void setErrorCode(String errorCode) {
  75. this.errorCode = errorCode;
  76. }
  77. public String getErrorDesc() {
  78. return errorDesc;
  79. }
  80. public void setErrorDesc(String errorDesc) {
  81. this.errorDesc = errorDesc;
  82. }
  83. public Object getRespJson() {
  84. return respJson;
  85. }
  86. public void setRespJson(Object respJson) {
  87. this.respJson = respJson;
  88. }
  89. }