
ars.invoke.convert.SimpleThrowableResolver Maven / Gradle / Ivy
The newest version!
package ars.invoke.convert;
/**
* 异常转换简单实现
*
* @author wuyongqiang
*/
public class SimpleThrowableResolver implements ThrowableResolver {
private Class> type;
private int code;
private String message;
public SimpleThrowableResolver(Class> type, int code) {
this(type, code, null);
}
public SimpleThrowableResolver(Class> type, int code, String message) {
if (type == null) {
throw new IllegalArgumentException("Type must not be null");
}
if (code < 500) {
throw new IllegalArgumentException("Code must not be leass than 500, got " + code);
}
this.type = type;
this.code = code;
this.message = message;
}
@Override
public int getCode(Throwable throwable) {
return this.code;
}
@Override
public String getMessage(Throwable throwable) {
return this.message == null ? throwable.getMessage() : this.message;
}
@Override
public boolean isResolvable(Throwable throwable) {
return throwable != null && this.type.isAssignableFrom(throwable.getClass());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy