Blame view

ruoyi-common/src/main/java/com/ruoyi/common/exception/BaseException.java 1.88 KB
46444bd0   RuoYi   RuoYi-Vue 1.0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
  package com.ruoyi.common.exception;

  

  import com.ruoyi.common.utils.MessageUtils;

  import com.ruoyi.common.utils.StringUtils;

  

  /**

   * 基础异常

   * 

   * @author ruoyi

   */

  public class BaseException extends RuntimeException

  {

      private static final long serialVersionUID = 1L;

  

      /**

       * 所属模块

       */

      private String module;

  

      /**

       * 错误码

       */

      private String code;

  

      /**

       * 错误码对应的参数

       */

      private Object[] args;

  

      /**

       * 错误消息

       */

      private String defaultMessage;

  

      public BaseException(String module, String code, Object[] args, String defaultMessage)

      {

          this.module = module;

          this.code = code;

          this.args = args;

          this.defaultMessage = defaultMessage;

      }

  

      public BaseException(String module, String code, Object[] args)

      {

          this(module, code, args, null);

      }

  

      public BaseException(String module, String defaultMessage)

      {

          this(module, null, null, defaultMessage);

      }

  

      public BaseException(String code, Object[] args)

      {

          this(null, code, args, null);

      }

  

      public BaseException(String defaultMessage)

      {

          this(null, null, null, defaultMessage);

      }

  

      @Override

      public String getMessage()

      {

          String message = null;

          if (!StringUtils.isEmpty(code))

          {

              message = MessageUtils.message(code, args);

          }

          if (message == null)

          {

              message = defaultMessage;

          }

          return message;

      }

  

      public String getModule()

      {

          return module;

      }

  

      public String getCode()

      {

          return code;

      }

  

      public Object[] getArgs()

      {

          return args;

      }

  

      public String getDefaultMessage()

      {

          return defaultMessage;

      }

  }