123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- package com.ruoyi.common.exception.base;
- import org.springframework.util.StringUtils;
- import com.ruoyi.common.utils.MessageUtils;
- /**
- * 基础异常
- *
- * @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;
- }
- @Override
- public String toString()
- {
- return this.getClass() + "{" + "module='" + module + '\'' + ", message='" + getMessage() + '\'' + '}';
- }
- }
|