com.github.antelopeframework.web.ajax.result.AjaxResultRunner Maven / Gradle / Ivy
The newest version!
package com.github.antelopeframework.web.ajax.result;
import org.apache.commons.lang3.exception.ExceptionUtils;
import lombok.extern.slf4j.Slf4j;
/**
*
* @author yangzhi
*
*/
@Slf4j
public abstract class AjaxResultRunner {
/**
*
* @param callback
* @return
*/
public static AjaxResult run(Callback callback) {
AjaxResult result = new AjaxResult();
try {
result.setSuccess(true);
Object value = callback.execute();
result.setData(value);
return result;
} catch (Exception e) {
if (log.isErrorEnabled()) {
log.error("Error : {}.", e);
}
Error error = new Error();
error.setDescription(ExceptionUtils.getRootCauseMessage(e));
error.setStackTrace(ExceptionUtils.getStackTrace(e));
result.setSuccess(false);
result.setError(error);
}
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy