增加RetException
This commit is contained in:
43
src/main/java/org/redkale/service/RetException.java
Normal file
43
src/main/java/org/redkale/service/RetException.java
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
*
|
||||
*/
|
||||
package org.redkale.service;
|
||||
|
||||
import org.redkale.util.RedkaleException;
|
||||
|
||||
/**
|
||||
* 错误码自定义异常类
|
||||
*
|
||||
* <p>详情见: https://redkale.org
|
||||
*
|
||||
* @author zhangjx
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public class RetException extends RedkaleException {
|
||||
|
||||
private int code;
|
||||
|
||||
public RetException(int code) {
|
||||
super(RetCodes.retInfo(code));
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public RetException(int code, String message) {
|
||||
super(message);
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public RetException(int code, Throwable cause) {
|
||||
super(RetCodes.retInfo(code), cause);
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public RetException(int code, String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
@@ -126,11 +126,21 @@ public class RetResult<T> implements Serializable {
|
||||
return new RetResult(retcode, retinfo);
|
||||
}
|
||||
|
||||
// @since 2.8.0
|
||||
public static <T> RetResult<T> fail(RetException ex) {
|
||||
return new RetResult(ex.getCode(), ex.getMessage());
|
||||
}
|
||||
|
||||
// @since 2.7.0
|
||||
public static <T> CompletableFuture<RetResult<T>> failFuture(int retcode, String retinfo) {
|
||||
return CompletableFuture.completedFuture(new RetResult(retcode, retinfo));
|
||||
}
|
||||
|
||||
// @since 2.8.0
|
||||
public static <T> CompletableFuture<RetResult<T>> failFuture(RetException ex) {
|
||||
return CompletableFuture.completedFuture(new RetResult(ex.getCode(), ex.getMessage()));
|
||||
}
|
||||
|
||||
// @since 2.7.0
|
||||
public T join() {
|
||||
if (isSuccess()) {
|
||||
|
||||
Reference in New Issue
Block a user