From 70b70c33870fb35f22595562723907dd95f733b8 Mon Sep 17 00:00:00 2001 From: kl Date: Sun, 18 Sep 2022 13:23:13 +0800 Subject: [PATCH] Refactoring the message splicing of internal Exceptions (#4571) * add tech-support-qq-4.png * Update README.md * Enhance the user experience in the scenario of submitting duplicate keys * Modify the key-value conflict exception prompt, adjust the code style * refactor(apollo): Refactoring the message splicing of internal Exceptions Co-authored-by: Jason Song --- .../controller/InstanceConfigController.java | 2 +- .../framework/apollo/biz/service/AppService.java | 2 +- .../framework/apollo/biz/service/ItemService.java | 4 ++-- .../framework/apollo/biz/service/ItemSetService.java | 4 ++-- .../framework/apollo/biz/service/ReleaseService.java | 4 ++-- .../exception/AbstractApolloHttpException.java | 8 ++++---- .../apollo/common/exception/NotFoundException.java | 4 ++-- .../apollo/openapi/service/ConsumerService.java | 2 +- .../openapi/v1/controller/ClusterController.java | 4 ++-- .../apollo/openapi/v1/controller/ItemController.java | 4 ++-- .../openapi/v1/controller/NamespaceController.java | 12 ++++++------ .../component/txtresolver/PropertyResolver.java | 2 +- .../apollo/portal/controller/ConsumerController.java | 2 +- .../portal/controller/NamespaceBranchController.java | 2 +- .../portal/controller/NamespaceController.java | 4 ++-- .../portal/controller/PermissionController.java | 2 +- .../apollo/portal/controller/ReleaseController.java | 4 ++-- .../apollo/portal/service/AppNamespaceService.java | 2 +- .../framework/apollo/portal/service/AppService.java | 8 ++++---- .../apollo/portal/service/ClusterService.java | 2 +- .../framework/apollo/portal/service/ItemService.java | 4 ++-- .../apollo/portal/service/NamespaceService.java | 2 +- 22 files changed, 42 insertions(+), 42 deletions(-) diff --git a/apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/InstanceConfigController.java b/apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/InstanceConfigController.java index 5cb53920cd4..c270e7219da 100644 --- a/apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/InstanceConfigController.java +++ b/apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/InstanceConfigController.java @@ -70,7 +70,7 @@ public PageDTO getByRelease(@RequestParam("releaseId") long release Pageable pageable) { Release release = releaseService.findOne(releaseId); if (release == null) { - throw new NotFoundException(String.format("release not found for %s", releaseId)); + throw new NotFoundException("release not found for %s", releaseId); } Page instanceConfigsPage = instanceService.findActiveInstanceConfigsByReleaseKey (release.getReleaseKey(), pageable); diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/AppService.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/AppService.java index c257d34320b..d12bd31681c 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/AppService.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/AppService.java @@ -92,7 +92,7 @@ public void update(App app) { App managedApp = appRepository.findByAppId(appId); if (managedApp == null) { - throw new BadRequestException(String.format("App not exists. AppId = %s", appId)); + throw new BadRequestException("App not exists. AppId = %s", appId); } managedApp.setName(app.getName()); diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemService.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemService.java index 7ffd427e9e9..fae2c9acda1 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemService.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemService.java @@ -224,8 +224,8 @@ private Namespace findNamespaceByAppIdAndClusterNameAndNamespaceName(String appI String namespaceName) { Namespace namespace = namespaceService.findOne(appId, clusterName, namespaceName); if (namespace == null) { - throw new NotFoundException(String.format("namespace not found for appId:%s clusterName:%s namespaceName:%s", - appId, clusterName, namespaceName)); + throw new NotFoundException("namespace not found for appId:%s clusterName:%s namespaceName:%s", + appId, clusterName, namespaceName); } return namespace; } diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemSetService.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemSetService.java index c2fd4b65e48..9ab7539546e 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemSetService.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemSetService.java @@ -62,7 +62,7 @@ public ItemChangeSets updateSet(String appId, String clusterName, Namespace namespace = namespaceService.findOne(appId, clusterName, namespaceName); if (namespace == null) { - throw new NotFoundException(String.format("Namespace %s not found", namespaceName)); + throw new NotFoundException("Namespace %s not found", namespaceName); } String operator = changeSet.getDataChangeLastModifiedBy(); @@ -112,7 +112,7 @@ private void doUpdateItems(List toUpdateItems, Namespace namespace, Str Item managedItem = itemService.findOne(entity.getId()); if (managedItem == null) { - throw new NotFoundException(String.format("item not found.(key=%s)", entity.getKey())); + throw new NotFoundException("item not found.(key=%s)", entity.getKey()); } if (managedItem.getNamespaceId() != namespace.getId()) { throw new BadRequestException("Invalid request, item and namespace do not match!"); diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ReleaseService.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ReleaseService.java index b38a570ae01..54a78e58423 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ReleaseService.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ReleaseService.java @@ -473,11 +473,11 @@ public Release rollback(long releaseId, String operator) { PageRequest page = PageRequest.of(0, 2); List twoLatestActiveReleases = findActiveReleases(appId, clusterName, namespaceName, page); if (twoLatestActiveReleases == null || twoLatestActiveReleases.size() < 2) { - throw new BadRequestException(String.format( + throw new BadRequestException( "Can't rollback namespace(appId=%s, clusterName=%s, namespaceName=%s) because there is only one active release", appId, clusterName, - namespaceName)); + namespaceName); } release.setAbandoned(true); diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/exception/AbstractApolloHttpException.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/exception/AbstractApolloHttpException.java index c91557ca0c2..ca49a501602 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/exception/AbstractApolloHttpException.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/exception/AbstractApolloHttpException.java @@ -27,13 +27,13 @@ public abstract class AbstractApolloHttpException extends RuntimeException{ /** * When args not empty, use {@link com.google.common.base.Strings#lenientFormat(String, Object...)} - * to replace %s in msgtpl with args to set the error message. Otherwise, use msgtpl + * to replace %s in msgTpl with args to set the error message. Otherwise, use msgTpl * to set the error message. e.g.: *
{@code new NotFoundException("... %s ... %s ... %s", "str", 0, 0.1)}
- * If the number of '%s' in `msgtpl` does not match args length, the '%s' string will be printed. + * If the number of '%s' in `msgTpl` does not match args length, the '%s' string will be printed. */ - public AbstractApolloHttpException(String msgtpl, Object... args){ - super(args == null || args.length == 0 ? msgtpl : Strings.lenientFormat(msgtpl, args)); + public AbstractApolloHttpException(String msgTpl, Object... args){ + super(args == null || args.length == 0 ? msgTpl : Strings.lenientFormat(msgTpl, args)); } public AbstractApolloHttpException(String msg, Exception e){ diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/exception/NotFoundException.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/exception/NotFoundException.java index c05288790fb..36e7f921297 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/exception/NotFoundException.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/exception/NotFoundException.java @@ -23,8 +23,8 @@ public class NotFoundException extends AbstractApolloHttpException { /** * @see AbstractApolloHttpException#AbstractApolloHttpException(String, Object...) */ - public NotFoundException(String msgtpl, Object... args) { - super(msgtpl, args); + public NotFoundException(String msgTpl, Object... args) { + super(msgTpl, args); setHttpStatus(HttpStatus.NOT_FOUND); } } diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/service/ConsumerService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/service/ConsumerService.java index 2ddcf8ecdea..b7d5bb85abd 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/service/ConsumerService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/service/ConsumerService.java @@ -104,7 +104,7 @@ public Consumer createConsumer(Consumer consumer) { String ownerName = consumer.getOwnerName(); UserInfo owner = userService.findByUserId(ownerName); if (owner == null) { - throw new BadRequestException(String.format("User does not exist. UserId = %s", ownerName)); + throw new BadRequestException("User does not exist. UserId = %s", ownerName); } consumer.setOwnerEmail(owner.getEmail()); diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/ClusterController.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/ClusterController.java index 0a43c079e25..5d1f6138dc4 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/ClusterController.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/ClusterController.java @@ -60,8 +60,8 @@ public OpenClusterDTO createCluster(@PathVariable String appId, @PathVariable St @Valid @RequestBody OpenClusterDTO cluster, HttpServletRequest request) { if (!Objects.equals(appId, cluster.getAppId())) { - throw new BadRequestException(String.format( - "AppId not equal. AppId in path = %s, AppId in payload = %s", appId, cluster.getAppId())); + throw new BadRequestException( + "AppId not equal. AppId in path = %s, AppId in payload = %s", appId, cluster.getAppId()); } String clusterName = cluster.getName(); diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/ItemController.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/ItemController.java index 7cdeb108719..e3c85163dc0 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/ItemController.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/ItemController.java @@ -92,7 +92,7 @@ public OpenItemDTO createItem(@PathVariable String appId, @PathVariable String e } if (!StringUtils.isEmpty(item.getComment()) && item.getComment().length() > ITEM_COMMENT_MAX_LENGTH) { - throw new BadRequestException(String.format("Comment length should not exceed %s characters", ITEM_COMMENT_MAX_LENGTH)); + throw new BadRequestException("Comment length should not exceed %s characters", ITEM_COMMENT_MAX_LENGTH); } return this.itemOpenApiService.createItem(appId, env, clusterName, namespaceName, item); @@ -118,7 +118,7 @@ public void updateItem(@PathVariable String appId, @PathVariable String env, } if (!StringUtils.isEmpty(item.getComment()) && item.getComment().length() > ITEM_COMMENT_MAX_LENGTH) { - throw new BadRequestException(String.format("Comment length should not exceed %s characters", ITEM_COMMENT_MAX_LENGTH)); + throw new BadRequestException("Comment length should not exceed %s characters", ITEM_COMMENT_MAX_LENGTH); } if (createIfNotExists) { diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/NamespaceController.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/NamespaceController.java index f7b87867d19..cafcbd1aa3a 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/NamespaceController.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/NamespaceController.java @@ -56,25 +56,25 @@ public OpenAppNamespaceDTO createNamespace(@PathVariable String appId, HttpServletRequest request) { if (!Objects.equals(appId, appNamespaceDTO.getAppId())) { - throw new BadRequestException(String.format("AppId not equal. AppId in path = %s, AppId in payload = %s", appId, - appNamespaceDTO.getAppId())); + throw new BadRequestException("AppId not equal. AppId in path = %s, AppId in payload = %s", appId, + appNamespaceDTO.getAppId()); } RequestPrecondition.checkArgumentsNotEmpty(appNamespaceDTO.getAppId(), appNamespaceDTO.getName(), appNamespaceDTO.getFormat(), appNamespaceDTO.getDataChangeCreatedBy()); if (!InputValidator.isValidAppNamespace(appNamespaceDTO.getName())) { - throw new BadRequestException(String.format("Invalid Namespace format: %s", + throw new BadRequestException("Invalid Namespace format: %s", InputValidator.INVALID_CLUSTER_NAMESPACE_MESSAGE + " & " - + InputValidator.INVALID_NAMESPACE_NAMESPACE_MESSAGE)); + + InputValidator.INVALID_NAMESPACE_NAMESPACE_MESSAGE); } if (!ConfigFileFormat.isValidFormat(appNamespaceDTO.getFormat())) { - throw new BadRequestException(String.format("Invalid namespace format. format = %s", appNamespaceDTO.getFormat())); + throw new BadRequestException("Invalid namespace format. format = %s", appNamespaceDTO.getFormat()); } String operator = appNamespaceDTO.getDataChangeCreatedBy(); if (userService.findByUserId(operator) == null) { - throw new BadRequestException(String.format("Illegal user. user = %s", operator)); + throw new BadRequestException("Illegal user. user = %s", operator); } return this.namespaceOpenApiService.createAppNamespace(appNamespaceDTO); diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/txtresolver/PropertyResolver.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/txtresolver/PropertyResolver.java index b9b56d7306b..1d8833630b6 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/txtresolver/PropertyResolver.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/txtresolver/PropertyResolver.java @@ -54,7 +54,7 @@ public ItemChangeSets resolve(long namespaceId, String configText, List String[] newItems = configText.split(ITEM_SEPARATOR); Set repeatKeys = new HashSet<>(); if (isHasRepeatKey(newItems, repeatKeys)) { - throw new BadRequestException(String.format("Config text has repeated keys: %s, please check your input.", repeatKeys)); + throw new BadRequestException("Config text has repeated keys: %s, please check your input.", repeatKeys); } ItemChangeSets changeSets = new ItemChangeSets(); diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ConsumerController.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ConsumerController.java index e8fee2a1d13..0b2ea4daf09 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ConsumerController.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ConsumerController.java @@ -105,7 +105,7 @@ public List assignNamespaceRoleToConsumer(@PathVariable String tok continue; } if (Env.UNKNOWN.equals(Env.transformEnv(env))) { - throw new BadRequestException(String.format("env: %s is illegal", env)); + throw new BadRequestException("env: %s is illegal", env); } envList.add(env); } diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/NamespaceBranchController.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/NamespaceBranchController.java index 2a8ba61e2f9..2405efe4198 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/NamespaceBranchController.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/NamespaceBranchController.java @@ -119,7 +119,7 @@ public ReleaseDTO merge(@PathVariable String appId, @PathVariable String env, @RequestBody NamespaceReleaseModel model) { if (model.isEmergencyPublish() && !portalConfig.isEmergencyPublishAllowed(Env.valueOf(env))) { - throw new BadRequestException(String.format("Env: %s is not supported emergency publish now", env)); + throw new BadRequestException("Env: %s is not supported emergency publish now", env); } ReleaseDTO createdRelease = namespaceBranchService.merge(appId, Env.valueOf(env), clusterName, namespaceName, branchName, diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/NamespaceController.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/NamespaceController.java index 9d2f286ef53..826efc48b68 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/NamespaceController.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/NamespaceController.java @@ -220,8 +220,8 @@ public AppNamespace createAppNamespace(@PathVariable String appId, @RequestParam(defaultValue = "true") boolean appendNamespacePrefix, @Valid @RequestBody AppNamespace appNamespace) { if (!InputValidator.isValidAppNamespace(appNamespace.getName())) { - throw new BadRequestException(String.format("Invalid Namespace format: %s", - InputValidator.INVALID_CLUSTER_NAMESPACE_MESSAGE + " & " + InputValidator.INVALID_NAMESPACE_NAMESPACE_MESSAGE)); + throw new BadRequestException("Invalid Namespace format: %s", + InputValidator.INVALID_CLUSTER_NAMESPACE_MESSAGE + " & " + InputValidator.INVALID_NAMESPACE_NAMESPACE_MESSAGE); } AppNamespace createdAppNamespace = appNamespaceService.createAppNamespaceInLocal(appNamespace, appendNamespacePrefix); diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/PermissionController.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/PermissionController.java index 271efdc1127..97134795295 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/PermissionController.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/PermissionController.java @@ -286,7 +286,7 @@ public ResponseEntity removeAppRoleFromUser(@PathVariable String appId, @P private void checkUserExists(String userId) { if (userService.findByUserId(userId) == null) { - throw new BadRequestException(String.format("User %s does not exist!", userId)); + throw new BadRequestException("User %s does not exist!", userId); } } diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ReleaseController.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ReleaseController.java index a4fb37abc7f..1166a0e945c 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ReleaseController.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ReleaseController.java @@ -80,7 +80,7 @@ public ReleaseDTO createRelease(@PathVariable String appId, model.setNamespaceName(namespaceName); if (model.isEmergencyPublish() && !portalConfig.isEmergencyPublishAllowed(Env.valueOf(env))) { - throw new BadRequestException(String.format("Env: %s is not supported emergency publish now", env)); + throw new BadRequestException("Env: %s is not supported emergency publish now", env); } ReleaseDTO createdRelease = releaseService.publish(model); @@ -110,7 +110,7 @@ public ReleaseDTO createGrayRelease(@PathVariable String appId, model.setNamespaceName(namespaceName); if (model.isEmergencyPublish() && !portalConfig.isEmergencyPublishAllowed(Env.valueOf(env))) { - throw new BadRequestException(String.format("Env: %s is not supported emergency publish now", env)); + throw new BadRequestException("Env: %s is not supported emergency publish now", env); } ReleaseDTO createdRelease = releaseService.publish(model); diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppNamespaceService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppNamespaceService.java index 42d4d9918cd..ce858b31d8f 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppNamespaceService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppNamespaceService.java @@ -97,7 +97,7 @@ public List findAll() { @Transactional public void createDefaultAppNamespace(String appId) { if (!isAppNamespaceNameUnique(appId, ConfigConsts.NAMESPACE_APPLICATION)) { - throw new BadRequestException(String.format("App already has application namespace. AppId = %s", appId)); + throw new BadRequestException("App already has application namespace. AppId = %s", appId); } AppNamespace appNs = new AppNamespace(); diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppService.java index 702375d070a..ba5b592f79e 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppService.java @@ -130,7 +130,7 @@ public App createAppInLocal(App app) { App managedApp = appRepository.findByAppId(appId); if (managedApp != null) { - throw new BadRequestException(String.format("App already exists. AppId = %s", appId)); + throw new BadRequestException("App already exists. AppId = %s", appId); } UserInfo owner = userService.findByUserId(app.getOwnerName()); @@ -178,7 +178,7 @@ public App updateAppInLocal(App app) { App managedApp = appRepository.findByAppId(appId); if (managedApp == null) { - throw new BadRequestException(String.format("App not exists. AppId = %s", appId)); + throw new BadRequestException("App not exists. AppId = %s", appId); } managedApp.setName(app.getName()); @@ -188,7 +188,7 @@ public App updateAppInLocal(App app) { String ownerName = app.getOwnerName(); UserInfo owner = userService.findByUserId(ownerName); if (owner == null) { - throw new BadRequestException(String.format("App's owner not exists. owner = %s", ownerName)); + throw new BadRequestException("App's owner not exists. owner = %s", ownerName); } managedApp.setOwnerName(owner.getUserId()); managedApp.setOwnerEmail(owner.getEmail()); @@ -209,7 +209,7 @@ public EnvClusterInfo createEnvNavNode(Env env, String appId) { public App deleteAppInLocal(String appId) { App managedApp = appRepository.findByAppId(appId); if (managedApp == null) { - throw new BadRequestException(String.format("App not exists. AppId = %s", appId)); + throw new BadRequestException("App not exists. AppId = %s", appId); } String operator = userInfoHolder.getUser().getUserId(); diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ClusterService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ClusterService.java index 1f502eb1902..83632138766 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ClusterService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ClusterService.java @@ -44,7 +44,7 @@ public List findClusters(Env env, String appId) { public ClusterDTO createCluster(Env env, ClusterDTO cluster) { if (!clusterAPI.isClusterUnique(cluster.getAppId(), env, cluster.getName())) { - throw new BadRequestException(String.format("cluster %s already exists.", cluster.getName())); + throw new BadRequestException("cluster %s already exists.", cluster.getName()); } ClusterDTO clusterDTO = clusterAPI.create(env, cluster); diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ItemService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ItemService.java index 64cfffa9ede..4b66d9cddbe 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ItemService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ItemService.java @@ -285,9 +285,9 @@ private long getNamespaceId(NamespaceIdentifier namespaceIdentifier) { namespaceDTO = namespaceAPI.loadNamespace(appId, env, clusterName, namespaceName); } catch (HttpClientErrorException e) { if (e.getStatusCode() == HttpStatus.NOT_FOUND) { - throw new BadRequestException(String.format( + throw new BadRequestException( "namespace not exist. appId:%s, env:%s, clusterName:%s, namespaceName:%s", appId, env, clusterName, - namespaceName)); + namespaceName); } throw e; } diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java index 15a35ca4924..a9fe506db42 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java @@ -178,7 +178,7 @@ public NamespaceDTO loadNamespaceBaseInfo(String appId, Env env, String clusterN String namespaceName) { NamespaceDTO namespace = namespaceAPI.loadNamespace(appId, env, clusterName, namespaceName); if (namespace == null) { - throw new BadRequestException(String.format("Namespace: %s not exist.", namespaceName)); + throw new BadRequestException("Namespace: %s not exist.", namespaceName); } return namespace; }