com.sinszm.common.exception.ApiException Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of szm-boot-common Show documentation
Show all versions of szm-boot-common Show documentation
基于SpringBoot扩展生态应用公共组件
Copyright © 2020 智慧程序猿 All rights reserved.
https://www.sinsz.com
package com.sinszm.common.exception;
import com.sinszm.common.Response;
import org.springframework.util.StringUtils;
/**
* 公共异常处理
*
* @author chenjianbo
*/
public class ApiException extends RuntimeException {
private ApiError apiError;
public ApiException() {
this(SystemApiError.SYSTEM_ERROR_01);
}
public ApiException(ApiError apiError) {
super(apiError.message());
this.apiError = apiError;
}
public ApiException(String errCode, String errMsg) {
super(errMsg == null ? "" : errMsg);
this.apiError = new ApiError() {
@Override
public String getCode() {
return StringUtils.isEmpty(errCode) ? "ERROR" : errCode.trim()
.replace(" ", "")
.replace("_", "-");
}
@Override
public String getMessage() {
return errMsg == null ? "" : errMsg;
}
};
}
private ApiError getApiError() {
return apiError;
}
public ApiError apiError() {
return this.getApiError();
}
@Override
public String toString() {
return Response.fail(
this.getApiError(),
super.getCause()
).toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy