Skip to content

Commit

Permalink
refactor: ♻️ 增加异常类构造器实现
Browse files Browse the repository at this point in the history
  • Loading branch information
fxbin committed Aug 28, 2023
1 parent 9555287 commit 7b868bb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@
* @version v1.0
* @since 2022/10/26 14:34
*/
@Getter
public class InvalidEnumValueException extends ServiceException{

@Getter
private int errcode;

@Getter
private String errmsg;

public InvalidEnumValueException() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@
* @version v1.0
* @since 2020/3/23 11:05
*/
@Getter
public class ServiceException extends RuntimeException {

private static final long serialVersionUID = 7366961732679791481L;

@Getter
private int errcode;

@Getter
private String errmsg;

public ServiceException(String errmsg) {
Expand All @@ -40,6 +37,12 @@ public ServiceException(Result<?> result) {
this.errmsg = result.getErrmsg();
}

public ServiceException(ResultCode resultCode) {
super(resultCode.getMsg());
this.errcode = resultCode.getCode();
this.errmsg = resultCode.getMsg();
}

public ServiceException(ResultCode resultCode, String errmsg, Object... args) {
super(LoggerMessageFormat.format(errmsg, args));
this.errcode = resultCode.getCode();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cn.fxbin.bubble.core.exception;

import cn.fxbin.bubble.core.logging.LoggerMessageFormat;
import cn.fxbin.bubble.core.model.ResultCode;
import lombok.Getter;

/**
Expand All @@ -10,12 +11,11 @@
* @version v1.0
* @since 2020/3/23 17:53
*/
@Getter
public class UtilException extends ServiceException {

@Getter
private int errcode;

@Getter
private String errmsg;

public UtilException(String errmsg) {
Expand All @@ -24,6 +24,12 @@ public UtilException(String errmsg) {
this.errmsg = errmsg;
}

public UtilException(ResultCode resultCode) {
super(resultCode.getMsg());
this.errcode = resultCode.getCode();
this.errmsg = resultCode.getMsg();
}

public UtilException(Integer errcode, String errmsg) {
super(errmsg);
this.errcode = errcode;
Expand Down

0 comments on commit 7b868bb

Please sign in to comment.