允许设置异常前缀
This commit is contained in:
parent
5710ff9afc
commit
7e413dfe69
@ -2,6 +2,7 @@ package cn.axzo.foundation.result;
|
|||||||
|
|
||||||
import cn.axzo.foundation.exception.BusinessException;
|
import cn.axzo.foundation.exception.BusinessException;
|
||||||
import cn.axzo.foundation.util.VarParamFormatter;
|
import cn.axzo.foundation.util.VarParamFormatter;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
public interface IResultCode {
|
public interface IResultCode {
|
||||||
|
|
||||||
@ -45,7 +46,12 @@ public interface IResultCode {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
default BusinessException toException(String customMsg) {
|
default BusinessException toException(String customMsg) {
|
||||||
return new BusinessException(getErrorCode(), customMsg);
|
String error = customMsg;
|
||||||
|
String prefix = getExceptionPrefix();
|
||||||
|
if (StringUtils.isNotBlank(prefix)) {
|
||||||
|
error = prefix + customMsg;
|
||||||
|
}
|
||||||
|
return new BusinessException(getErrorCode(), error);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -68,4 +74,7 @@ public interface IResultCode {
|
|||||||
return toException(msg);
|
return toException(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default String getExceptionPrefix() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,7 +36,7 @@ public class RpcClientImpl implements RpcClient {
|
|||||||
Optional<String> resp = requestBySupplier(requestParams, () -> this.getHttpClient().execute(httpMethod, url, requestParams));
|
Optional<String> resp = requestBySupplier(requestParams, () -> this.getHttpClient().execute(httpMethod, url, requestParams));
|
||||||
ApiResult<T> result = converter.apply(resp.orElse(StringUtils.EMPTY));
|
ApiResult<T> result = converter.apply(resp.orElse(StringUtils.EMPTY));
|
||||||
if (!result.isSuccess()) {
|
if (!result.isSuccess()) {
|
||||||
throw new BusinessException(result.getCode(), result.getMsg());
|
throw new BusinessException(result.getCode(), "业务异常: " + result.getMsg());
|
||||||
}
|
}
|
||||||
return result.getData();
|
return result.getData();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user