Search in sources :

Example 1 with FieldException

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());
}
Also used : FieldException(com.baidu.dsp.common.exception.FieldException) Config(com.baidu.disconf.web.service.config.bo.Config)

Example 2 with FieldException

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);
    }
}
Also used : App(com.baidu.disconf.web.service.app.bo.App) FieldException(com.baidu.dsp.common.exception.FieldException) Config(com.baidu.disconf.web.service.config.bo.Config) Env(com.baidu.disconf.web.service.env.bo.Env)

Example 3 with FieldException

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;
}
Also used : FieldException(com.baidu.dsp.common.exception.FieldException) Config(com.baidu.disconf.web.service.config.bo.Config)

Example 4 with FieldException

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());
}
Also used : App(com.baidu.disconf.web.service.app.bo.App) FieldException(com.baidu.dsp.common.exception.FieldException) ConfigFullModel(com.baidu.disconf.web.web.config.dto.ConfigFullModel) Env(com.baidu.disconf.web.service.env.bo.Env)

Example 5 with FieldException

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);
    }
}
Also used : AccessDeniedException(com.baidu.dsp.common.exception.AccessDeniedException) FieldException(com.baidu.dsp.common.exception.FieldException) DocumentNotFoundException(com.baidu.dsp.common.exception.DocumentNotFoundException) GlobalExceptionAware(com.baidu.dsp.common.exception.base.GlobalExceptionAware) TypeMismatchException(org.springframework.beans.TypeMismatchException) InvalidPropertyException(org.springframework.beans.InvalidPropertyException) BindException(org.springframework.validation.BindException) IOException(java.io.IOException) MissingServletRequestParameterException(org.springframework.web.bind.MissingServletRequestParameterException) HttpRequestMethodNotSupportedException(org.springframework.web.HttpRequestMethodNotSupportedException)

Aggregations

FieldException (com.baidu.dsp.common.exception.FieldException)7 App (com.baidu.disconf.web.service.app.bo.App)3 Config (com.baidu.disconf.web.service.config.bo.Config)3 Env (com.baidu.disconf.web.service.env.bo.Env)3 ConfigFullModel (com.baidu.disconf.web.web.config.dto.ConfigFullModel)2 User (com.baidu.disconf.web.service.user.bo.User)1 Visitor (com.baidu.disconf.web.service.user.dto.Visitor)1 AccessDeniedException (com.baidu.dsp.common.exception.AccessDeniedException)1 DocumentNotFoundException (com.baidu.dsp.common.exception.DocumentNotFoundException)1 GlobalExceptionAware (com.baidu.dsp.common.exception.base.GlobalExceptionAware)1 IOException (java.io.IOException)1 InvalidPropertyException (org.springframework.beans.InvalidPropertyException)1 TypeMismatchException (org.springframework.beans.TypeMismatchException)1 BindException (org.springframework.validation.BindException)1 HttpRequestMethodNotSupportedException (org.springframework.web.HttpRequestMethodNotSupportedException)1 MissingServletRequestParameterException (org.springframework.web.bind.MissingServletRequestParameterException)1