com.gitee.easyopen.exception.DefaultEasyopenExceptionHandler Maven / Gradle / Ivy
package com.gitee.easyopen.exception;
import com.gitee.easyopen.ApiConfig;
import com.gitee.easyopen.Result;
import com.gitee.easyopen.ResultCreator;
import com.gitee.easyopen.message.Errors;
/**
* @author tanghc
*/
public class DefaultEasyopenExceptionHandler implements EasyopenExceptionHandler {
@Override
public Result causeException(ResultCreator resultCreator, Throwable e) {
String code = Errors.SYS_ERROR.getCode();
String msg = e.getMessage();
Object data = null;
if (e instanceof ApiException) {
ApiException apiEx = (ApiException) e;
code = apiEx.getCode();
msg = apiEx.getMessage();
data = apiEx.getData();
}
return resultCreator.createErrorResult(code, msg, data);
}
}