use of com.baidu.dsp.common.exception.FieldException in project disconf by knightliao.
the class ConfigValidator method validateDelete.
/**
* 验证删除
*/
public void validateDelete(Long configId) {
Config config = configMgr.getConfigById(configId);
if (config == null) {
throw new FieldException("configId", "config.not.exist", null);
}
//
validateAppAuth(config.getAppId());
}
use of com.baidu.dsp.common.exception.FieldException in project disconf by knightliao.
the class ConfigValidator method validateNew.
/**
* 校验新建 配置
*
* @param confNewForm
* @param disConfigTypeEnum
*/
public void validateNew(ConfNewItemForm confNewForm, DisConfigTypeEnum disConfigTypeEnum) {
//
// app
//
App app = appMgr.getById(confNewForm.getAppId());
if (app == null) {
throw new FieldException(ConfNewForm.APPID, "app.not.exist", null);
}
//
validateAppAuth(app.getId());
//
// env
//
Env env = envMgr.getById(confNewForm.getEnvId());
if (env == null) {
throw new FieldException(ConfNewForm.ENVID, "env.not.exist", null);
}
//
// key
//
Config config = configFetchMgr.getConfByParameter(app.getId(), env.getId(), confNewForm.getVersion(), confNewForm.getKey(), disConfigTypeEnum);
if (config != null) {
throw new FieldException(ConfNewItemForm.KEY, "key.exist", null);
}
}
use of com.baidu.dsp.common.exception.FieldException in project disconf by knightliao.
the class ConfigValidator method valideConfigExist.
/**
* 校验
*
* @param id
*
* @return
*/
public Config valideConfigExist(Long id) {
//
// config
//
Config config = configMgr.getConfigById(id);
if (config == null) {
throw new FieldException("configId", "config.id.not.exist", null);
}
//
// validate app
//
validateAppAuth(config.getAppId());
return config;
}
use of com.baidu.dsp.common.exception.FieldException in project disconf by knightliao.
the class ConfigValidator4Fetch method verifyConfForm.
/**
* 此接口是客户的接口,非常 重要,目前没有权限的控制
*
* @param confForm
*/
public ConfigFullModel verifyConfForm(ConfForm confForm, boolean unCheckKey) {
//
if (StringUtils.isEmpty(confForm.getApp())) {
throw new FieldException("app", "app is empty", null);
}
App app = appMgr.getByName(confForm.getApp());
if (app == null) {
throw new FieldException("app", "app " + confForm.getApp() + " doesn't exist in db.", null);
}
//
if (StringUtils.isEmpty(confForm.getEnv())) {
throw new FieldException("env", "env is empty", null);
}
Env env = envMgr.getByName(confForm.getEnv());
if (env == null) {
throw new FieldException("env", "env " + confForm.getEnv() + " doesn't exist in db.", null);
}
//
if (!unCheckKey && StringUtils.isEmpty(confForm.getKey())) {
throw new FieldException("key", "key is empty", null);
}
//
if (StringUtils.isEmpty(confForm.getVersion())) {
throw new FieldException("version", "version is empty", null);
}
return new ConfigFullModel(app, env, confForm.getVersion(), confForm.getKey());
}
use of com.baidu.dsp.common.exception.FieldException in project disconf by knightliao.
the class MyExceptionHandler method resolveException.
@Override
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object o, Exception e) {
LOG.warn(request.getRequestURI() + " ExceptionHandler FOUND. " + e.toString() + "\t" + e.getCause());
// PathVariable 出错
if (e instanceof TypeMismatchException) {
return getParamErrors((TypeMismatchException) e);
// Bean 参数无法映射错误
} else if (e instanceof InvalidPropertyException) {
return getParamErrors((InvalidPropertyException) e);
// @Valid 出错
} else if (e instanceof BindException) {
return ParamValidateUtils.getParamErrors((BindException) e);
// 业务校验处理
} else if (e instanceof FieldException) {
return getParamErrors((FieldException) e);
} else if (e instanceof DocumentNotFoundException) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
try {
FileUtils.closeWriter(response.getWriter());
} catch (IOException e1) {
e1.printStackTrace();
}
return null;
// 用户没有请求方法的访问权限
} else if (e instanceof AccessDeniedException) {
LOG.warn("details: " + ((AccessDeniedException) e).getErrorMessage());
return buildError("auth.access.denied", ErrorCode.ACCESS_NOAUTH_ERROR);
} else if (e instanceof HttpRequestMethodNotSupportedException) {
return buildError("syserror.httpmethod", ErrorCode.HttpRequestMethodNotSupportedException);
} else if (e instanceof MissingServletRequestParameterException) {
return buildError("syserror.param.miss", ErrorCode.MissingServletRequestParameterException);
} else if (e instanceof GlobalExceptionAware) {
LOG.error("details: ", e);
GlobalExceptionAware g = (GlobalExceptionAware) e;
return buildError(g.getErrorMessage(), g.getErrorCode());
} else {
LOG.warn("details: ", e);
return buildError("syserror.inner", ErrorCode.GLOBAL_ERROR);
}
}
Aggregations