Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor NotFoundException、BadRequestException #4812

Merged
merged 88 commits into from
Mar 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
fe75b4d
add tech-support-qq-4.png
klboke May 16, 2019
99bf97a
Update README.md
klboke May 16, 2019
1579f41
Merge remote-tracking branch 'upstream/master'
klboke Nov 11, 2020
9f65eed
Merge remote-tracking branch 'upstream/master'
klboke Dec 9, 2020
d7d3fd9
Enhance the user experience in the scenario of submitting duplicate keys
klboke Dec 11, 2020
7329fab
Merge branch 'master' into master
nobodyiam Dec 12, 2020
5def448
Modify the key-value conflict exception prompt, adjust the code style
klboke Dec 12, 2020
6942564
Merge branch 'master' into master
nobodyiam Dec 12, 2020
0fc1f91
Merge remote-tracking branch 'upstream/master'
klboke Dec 19, 2020
61ad016
Merge remote-tracking branch 'origin/master'
klboke Dec 19, 2020
587ce33
rge remote-tracking branch 'upstream/master'
klboke Mar 1, 2021
9de6563
Merge remote-tracking branch 'upstream/master'
klboke Mar 8, 2021
9aab632
Merge remote-tracking branch 'upstream/master'
klboke Mar 25, 2021
050dd0a
Merge branch 'ctripcorp:master' into master
klboke May 10, 2021
5a64035
Merge branch 'master' of github.com:klboke/apollo
klboke May 10, 2021
0648fbd
Merge branch 'ctripcorp:master' into master
klboke May 19, 2021
35bd3a6
Merge branch 'master' of github.com:klboke/apollo
klboke May 19, 2021
bc8149b
Merge branch 'ctripcorp:master' into master
klboke Jun 8, 2021
e771bdd
Merge branch 'master' of github.com:klboke/apollo
klboke Jun 8, 2021
9a1ad83
Merge branch 'ctripcorp:master' into master
klboke Jun 25, 2021
3efef37
Merge branch 'master' of github.com:klboke/apollo
klboke Jun 25, 2021
1274281
Merge branch 'apolloconfig:master' into master
klboke Sep 1, 2021
a968932
Merge branch 'master' of github.com:klboke/apollo
klboke Sep 1, 2021
df8942c
Merge branch 'apolloconfig:master' into master
klboke Jan 7, 2022
f98175a
Merge branch 'master' of github.com:klboke/apollo
klboke Jan 7, 2022
710cdd6
Merge branch 'apolloconfig:master' into master
klboke Feb 18, 2022
3c162b6
Merge branch 'master' of github.com:klboke/apollo
klboke Feb 18, 2022
0101a3f
Merge branch 'apolloconfig:master' into master
klboke Jun 17, 2022
cc6f568
Merge branch 'master' of github.com:klboke/apollo
klboke Jun 17, 2022
21dd30c
Merge branch 'apolloconfig:master' into master
klboke Jun 21, 2022
c1eeb41
Merge branch 'master' of github.com:klboke/apollo
klboke Jun 21, 2022
e85d645
Merge branch 'apolloconfig:master' into master
klboke Jun 27, 2022
8b0056d
Merge branch 'master' of github.com:klboke/apollo
klboke Jun 27, 2022
347e07b
Merge branch 'apolloconfig:master' into master
klboke Jul 1, 2022
d8eb437
Merge branch 'master' of github.com:klboke/apollo
klboke Jul 1, 2022
19bae52
Merge branch 'apolloconfig:master' into master
klboke Jul 4, 2022
7e40fa1
Merge branch 'master' of github.com:klboke/apollo
klboke Jul 4, 2022
fbbb02d
Merge branch 'apolloconfig:master' into master
klboke Jul 6, 2022
19cee24
Merge branch 'master' of github.com:klboke/apollo
klboke Jul 6, 2022
91ba3b7
Merge branch 'apolloconfig:master' into master
klboke Jul 8, 2022
94ad542
Merge branch 'master' of github.com:klboke/apollo
klboke Jul 8, 2022
64e1b0b
Merge branch 'apolloconfig:master' into master
klboke Jul 19, 2022
36ce5e2
Merge branch 'master' of github.com:klboke/apollo
klboke Jul 19, 2022
c1364c2
Merge branch 'apolloconfig:master' into master
klboke Jul 22, 2022
76ed2ea
Merge branch 'master' of github.com:klboke/apollo
klboke Jul 22, 2022
db8cf3d
Merge branch 'apolloconfig:master' into master
klboke Jul 26, 2022
3e4616d
Merge branch 'master' of github.com:klboke/apollo
klboke Jul 26, 2022
47297cc
Merge branch 'apolloconfig:master' into master
klboke Jul 30, 2022
1c320e7
Merge branch 'apolloconfig:master' into master
klboke Aug 2, 2022
e723db5
Merge branch 'master' of github.com:klboke/apollo
klboke Aug 2, 2022
6be6a8b
Merge branch 'apolloconfig:master' into master
klboke Aug 8, 2022
014657d
Merge branch 'apolloconfig:master' into master
klboke Aug 12, 2022
370eec9
Merge branch 'master' of github.com:klboke/apollo
klboke Aug 12, 2022
dfa6c54
Merge branch 'apolloconfig:master' into master
klboke Sep 8, 2022
1a66d08
Merge branch 'master' of github.com:klboke/apollo
klboke Sep 8, 2022
cb2c22e
Merge branch 'apolloconfig:master' into master
klboke Sep 14, 2022
74af869
Merge branch 'master' of github.com:klboke/apollo
klboke Sep 14, 2022
a349f2e
Merge branch 'apolloconfig:master' into master
klboke Sep 22, 2022
7238296
Merge branch 'master' of github.com:klboke/apollo
klboke Sep 22, 2022
c38d00d
Merge branch 'apolloconfig:master' into master
klboke Oct 8, 2022
10cbbed
Merge branch 'master' of github.com:klboke/apollo
klboke Oct 8, 2022
601e17b
Merge branch 'apolloconfig:master' into master
klboke Oct 11, 2022
8fe2ce5
Merge branch 'master' of github.com:klboke/apollo
klboke Oct 11, 2022
04ea7ff
Merge branch 'apolloconfig:master' into master
klboke Dec 12, 2022
cfe577c
Merge branch 'master' of github.com:klboke/apollo
klboke Dec 12, 2022
4e9ba79
Merge branch 'apolloconfig:master' into master
klboke Dec 15, 2022
53d033a
Merge branch 'master' of github.com:klboke/apollo
klboke Dec 15, 2022
3789a6d
Merge branch 'apolloconfig:master' into master
klboke Jan 4, 2023
2a1f3bc
Merge branch 'master' of github.com:klboke/apollo
klboke Jan 10, 2023
0c7c63f
Merge branch 'apolloconfig:master' into master
klboke Mar 9, 2023
eaf3b3d
Merge branch 'master' of github.com:klboke/apollo
klboke Mar 9, 2023
312abaa
Merge branch 'apolloconfig:master' into master
klboke Mar 13, 2023
f7c95f2
Merge branch 'master' of github.com:klboke/apollo
klboke Mar 13, 2023
39cc719
Merge branch 'apolloconfig:master' into master
klboke Mar 15, 2023
e410062
Merge branch 'master' of github.com:klboke/apollo
klboke Mar 15, 2023
bb2bf94
Merge branch 'apolloconfig:master' into master
klboke Mar 17, 2023
95cf566
Merge branch 'master' of github.com:klboke/apollo
klboke Mar 17, 2023
0c10b9d
Merge branch 'apolloconfig:master' into master
klboke Mar 20, 2023
aa95cdd
Merge branch 'master' of github.com:klboke/apollo
klboke Mar 20, 2023
3441587
Merge branch 'apolloconfig:master' into master
klboke Mar 21, 2023
a09b174
Merge branch 'master' of github.com:klboke/apollo
klboke Mar 21, 2023
9d6f789
refactor(apollo-common): Refactor NotFoundException
klboke Mar 21, 2023
80c87e6
refactor(apollo-common): Add license
klboke Mar 21, 2023
ba758f4
refactor(apollo-common): Refactor BadRequestException
klboke Mar 22, 2023
dcea183
Merge branch 'master' into eception
nobodyiam Mar 23, 2023
88262a6
refactor(apollo-common): Refactor NotFoundException
klboke Mar 23, 2023
ccc55e4
Merge remote-tracking branch 'origin/eception' into eception
klboke Mar 23, 2023
0fe74cf
Merge branch 'master' into eception
nobodyiam Mar 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void requireLockAdvice(String appId, String clusterName, String namespace
public void requireLockAdvice(long itemId, String operator) {
Item item = itemService.findOne(itemId);
if (item == null){
throw new BadRequestException("item not exist.");
throw BadRequestException.itemNotExists(itemId);
}
acquireLock(item.getNamespaceId(), operator);
}
Expand Down Expand Up @@ -117,7 +117,7 @@ void acquireLock(long namespaceId, String currentUser) {

private void acquireLock(Namespace namespace, String currentUser) {
if (namespace == null) {
throw new BadRequestException("namespace not exist.");
throw BadRequestException.namespaceNotExists();
nobodyiam marked this conversation as resolved.
Show resolved Hide resolved
}

long namespaceId = namespace.getId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void requireLockAdvice(String appId, String clusterName, String namespace
public void requireLockAdvice(long itemId, String operator) {
Item item = itemService.findOne(itemId);
if (item == null) {
throw new BadRequestException("item not exist.");
throw BadRequestException.itemNotExists(itemId);
}
tryUnlock(namespaceService.findOne(item.getNamespaceId()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public AppDTO create(@Valid @RequestBody AppDTO dto) {
App entity = BeanUtils.transform(App.class, dto);
App managedEntity = appService.findOne(entity.getAppId());
if (managedEntity != null) {
throw new BadRequestException("app already exist.");
throw BadRequestException.appAlreadyExists(entity.getAppId());
}

entity = adminService.createNewApp(entity);
Expand All @@ -66,7 +66,7 @@ public AppDTO create(@Valid @RequestBody AppDTO dto) {
public void delete(@PathVariable("appId") String appId, @RequestParam String operator) {
App entity = appService.findOne(appId);
if (entity == null) {
throw new NotFoundException("app not found for appId " + appId);
throw NotFoundException.appNotFound(appId);
}
adminService.deleteApp(entity, operator);
}
Expand Down Expand Up @@ -96,7 +96,7 @@ public List<AppDTO> find(@RequestParam(value = "name", required = false) String
public AppDTO get(@PathVariable("appId") String appId) {
App app = appService.findOne(appId);
if (app == null) {
throw new NotFoundException("app not found for appId " + appId);
throw NotFoundException.appNotFound(appId);
}
return BeanUtils.transform(AppDTO.class, app);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public AppNamespaceDTO create(@RequestBody AppNamespaceDTO appNamespace,

entity = managedEntity;
} else {
throw new BadRequestException("app namespaces already exist.");
throw BadRequestException.appNamespaceAlreadyExists(entity.getAppId(), entity.getName());
}

return BeanUtils.transform(AppNamespaceDTO.class, entity);
Expand All @@ -80,7 +80,7 @@ public void delete(@PathVariable("appId") String appId, @PathVariable("namespace
@RequestParam String operator) {
AppNamespace entity = appNamespaceService.findOne(appId, namespaceName);
if (entity == null) {
throw new BadRequestException("app namespace not found for appId: " + appId + " namespace: " + namespaceName);
throw BadRequestException.appNamespaceNotExists(appId, namespaceName);
}
appNamespaceService.deleteAppNamespace(entity, operator);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public ClusterDTO create(@PathVariable("appId") String appId,
Cluster entity = BeanUtils.transform(Cluster.class, dto);
Cluster managedEntity = clusterService.findOne(appId, entity.getName());
if (managedEntity != null) {
throw new BadRequestException("cluster already exist.");
throw BadRequestException.clusterAlreadyExists(entity.getName());
}

if (autoCreatePrivateNamespace) {
Expand All @@ -69,7 +69,7 @@ public void delete(@PathVariable("appId") String appId,
Cluster entity = clusterService.findOne(appId, clusterName);

if (entity == null) {
throw new NotFoundException("cluster not found for clusterName " + clusterName);
throw NotFoundException.clusterNotFound(appId, clusterName);
}

if(ConfigConsts.CLUSTER_NAME_DEFAULT.equals(entity.getName())){
Expand All @@ -90,7 +90,7 @@ public ClusterDTO get(@PathVariable("appId") String appId,
@PathVariable("clusterName") String clusterName) {
Cluster cluster = clusterService.findOne(appId, clusterName);
if (cluster == null) {
throw new NotFoundException("cluster not found for name " + clusterName);
throw NotFoundException.clusterNotFound(appId, clusterName);
}
return BeanUtils.transform(ClusterDTO.class, cluster);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public PageDTO<InstanceDTO> getByRelease(@RequestParam("releaseId") long release
Pageable pageable) {
Release release = releaseService.findOne(releaseId);
if (release == null) {
throw new NotFoundException("release not found for %s", releaseId);
throw NotFoundException.releaseNotFound(releaseId);
}
Page<InstanceConfig> instanceConfigsPage = instanceService.findActiveInstanceConfigsByReleaseKey
(release.getReleaseKey(), pageable);
Expand Down Expand Up @@ -123,7 +123,7 @@ public List<InstanceDTO> getByReleasesNotIn(@RequestParam("appId") String appId,
List<Release> releases = releaseService.findByReleaseIds(releaseIdSet);

if (CollectionUtils.isEmpty(releases)) {
throw new NotFoundException("releases not found for %s", releaseIds);
throw NotFoundException.releaseNotFound(releaseIds);
}

Set<String> releaseKeys = releases.stream().map(Release::getReleaseKey).collect(Collectors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public ItemDTO create(@PathVariable("appId") String appId,

Item managedEntity = itemService.findOne(appId, clusterName, namespaceName, entity.getKey());
if (managedEntity != null) {
throw new BadRequestException("item already exists");
throw BadRequestException.itemAlreadyExists(entity.getKey());
}
entity = itemService.save(entity);
dto = BeanUtils.transform(ItemDTO.class, entity);
Expand Down Expand Up @@ -122,13 +122,13 @@ public ItemDTO update(@PathVariable("appId") String appId,
@RequestBody ItemDTO itemDTO) {
Item managedEntity = itemService.findOne(itemId);
if (managedEntity == null) {
throw new NotFoundException("item not found for itemId " + itemId);
throw NotFoundException.itemNotFound(appId, clusterName, namespaceName, itemId);
}

Namespace namespace = namespaceService.findOne(appId, clusterName, namespaceName);
// In case someone constructs an attack scenario
if (namespace == null || namespace.getId() != managedEntity.getNamespaceId()) {
throw new BadRequestException("Invalid request, item and namespace do not match!");
throw BadRequestException.namespaceNotMatch();
}

Item entity = BeanUtils.transform(Item.class, itemDTO);
Expand Down Expand Up @@ -159,7 +159,7 @@ public ItemDTO update(@PathVariable("appId") String appId,
public void delete(@PathVariable("itemId") long itemId, @RequestParam String operator) {
Item entity = itemService.findOne(itemId);
if (entity == null) {
throw new NotFoundException("item not found for itemId " + itemId);
throw NotFoundException.itemNotFound(itemId);
}
itemService.delete(entity.getId(), operator);

Expand Down Expand Up @@ -205,7 +205,7 @@ public List<ItemDTO> findDeletedItems(@PathVariable("appId") String appId,
public ItemDTO get(@PathVariable("itemId") long itemId) {
Item item = itemService.findOne(itemId);
if (item == null) {
throw new NotFoundException("item not found for itemId " + itemId);
throw NotFoundException.itemNotFound(itemId);
}
return BeanUtils.transform(ItemDTO.class, item);
}
Expand All @@ -216,8 +216,7 @@ public ItemDTO get(@PathVariable("appId") String appId,
@PathVariable("namespaceName") String namespaceName, @PathVariable("key") String key) {
Item item = itemService.findOne(appId, clusterName, namespaceName, key);
if (item == null) {
throw new NotFoundException("item not found for %s %s %s %s", appId, clusterName,
namespaceName, key);
throw NotFoundException.itemNotFound(appId, clusterName, namespaceName, key);
}
return BeanUtils.transform(ItemDTO.class, item);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,7 @@ private void checkBranch(String appId, String clusterName, String namespaceName,
private void checkNamespace(String appId, String clusterName, String namespaceName) {
Namespace parentNamespace = namespaceService.findOne(appId, clusterName, namespaceName);
if (parentNamespace == null) {
throw new BadRequestException(
"Namespace not exist. AppId = %s, ClusterName = %s, NamespaceName = %s", appId,
clusterName, namespaceName);
throw BadRequestException.namespaceNotExists(appId, clusterName, namespaceName);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public NamespaceDTO create(@PathVariable("appId") String appId,
Namespace entity = BeanUtils.transform(Namespace.class, dto);
Namespace managedEntity = namespaceService.findOne(appId, clusterName, entity.getNamespaceName());
if (managedEntity != null) {
throw new BadRequestException("namespace already exist.");
throw BadRequestException.namespaceAlreadyExists(entity.getNamespaceName());
}

entity = namespaceService.save(entity);
Expand All @@ -68,8 +68,7 @@ public void delete(@PathVariable("appId") String appId,
@PathVariable("namespaceName") String namespaceName, @RequestParam String operator) {
Namespace entity = namespaceService.findOne(appId, clusterName, namespaceName);
if (entity == null) {
throw new NotFoundException("namespace not found for %s %s %s", appId, clusterName,
namespaceName);
throw NotFoundException.namespaceNotFound(appId, clusterName, namespaceName);
}

namespaceService.deleteNamespace(entity, operator);
Expand All @@ -86,7 +85,7 @@ public List<NamespaceDTO> find(@PathVariable("appId") String appId,
public NamespaceDTO get(@PathVariable("namespaceId") Long namespaceId) {
Namespace namespace = namespaceService.findOne(namespaceId);
if (namespace == null) {
throw new NotFoundException("namespace not found for %s", namespaceId);
throw NotFoundException.itemNotFound(namespaceId);
}
return BeanUtils.transform(NamespaceDTO.class, namespace);
}
Expand All @@ -109,8 +108,7 @@ public NamespaceDTO get(@PathVariable("appId") String appId,
@PathVariable("namespaceName") String namespaceName) {
Namespace namespace = namespaceService.findOne(appId, clusterName, namespaceName);
if (namespace == null) {
throw new NotFoundException("namespace not found for %s %s %s", appId, clusterName,
namespaceName);
throw NotFoundException.namespaceNotFound(appId, clusterName, namespaceName);
}
return BeanUtils.transform(NamespaceDTO.class, namespace);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public NamespaceLockDTO getNamespaceLockOwner(@PathVariable String appId, @PathV
@PathVariable String namespaceName) {
Namespace namespace = namespaceService.findOne(appId, clusterName, namespaceName);
if (namespace == null) {
throw new BadRequestException("namespace not exist.");
throw BadRequestException.namespaceNotExists(appId, clusterName, namespaceName);
}

if (bizConfig.isNamespaceLockSwitchOff()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public ReleaseController(
public ReleaseDTO get(@PathVariable("releaseId") long releaseId) {
Release release = releaseService.findOne(releaseId);
if (release == null) {
throw new NotFoundException("release not found for %s", releaseId);
throw NotFoundException.releaseNotFound(releaseId);
}
return BeanUtils.transform(ReleaseDTO.class, release);
}
Expand Down Expand Up @@ -125,8 +125,7 @@ public ReleaseDTO publish(@PathVariable("appId") String appId,
@RequestParam(name = "isEmergencyPublish", defaultValue = "false") boolean isEmergencyPublish) {
Namespace namespace = namespaceService.findOne(appId, clusterName, namespaceName);
if (namespace == null) {
throw new NotFoundException("Could not find namespace for %s %s %s", appId, clusterName,
namespaceName);
throw NotFoundException.namespaceNotFound(appId, clusterName, namespaceName);
}
Release release = releaseService.publish(namespace, releaseName, releaseComment, operator, isEmergencyPublish);

Expand Down Expand Up @@ -162,8 +161,7 @@ public ReleaseDTO updateAndPublish(@PathVariable("appId") String appId,
@RequestBody ItemChangeSets changeSets) {
Namespace namespace = namespaceService.findOne(appId, clusterName, namespaceName);
if (namespace == null) {
throw new NotFoundException("Could not find namespace for %s %s %s", appId, clusterName,
namespaceName);
throw NotFoundException.namespaceNotFound(appId, clusterName, namespaceName);
}

Release release = releaseService.mergeBranchChangeSetsAndRelease(namespace, branchName, releaseName,
Expand Down Expand Up @@ -214,11 +212,10 @@ public ReleaseDTO publish(@PathVariable("appId") String appId,
@RequestParam(name = "grayDelKeys") Set<String> grayDelKeys){
Namespace namespace = namespaceService.findOne(appId, clusterName, namespaceName);
if (namespace == null) {
throw new NotFoundException("Could not find namespace for %s %s %s", appId, clusterName,
namespaceName);
throw NotFoundException.namespaceNotFound(appId, clusterName, namespaceName);
}

Release release = releaseService.grayDeletionPublish(namespace, releaseName, releaseComment,
Release release = releaseService.grayDeletionPublish(namespace, releaseName, releaseComment,
operator, isEmergencyPublish, grayDelKeys);

//send release message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public AccessKey update(String appId, AccessKey entity) {

AccessKey accessKey = accessKeyRepository.findOneByAppIdAndId(appId, id);
if (accessKey == null) {
throw new BadRequestException("AccessKey not exist");
throw BadRequestException.accessKeyNotExists();
}

accessKey.setEnabled(entity.isEnabled());
Expand All @@ -86,7 +86,7 @@ public AccessKey update(String appId, AccessKey entity) {
public void delete(String appId, long id, String operator) {
AccessKey accessKey = accessKeyRepository.findOneByAppIdAndId(appId, id);
if (accessKey == null) {
throw new BadRequestException("AccessKey not exist");
throw BadRequestException.accessKeyNotExists();
}

if (accessKey.isEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void update(App app) {

App managedApp = appRepository.findByAppId(appId);
if (managedApp == null) {
throw new BadRequestException("App not exists. AppId = %s", appId);
throw BadRequestException.appNotExists(appId);
}

managedApp.setName(app.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public Cluster saveWithoutInstanceOfAppNamespaces(Cluster entity) {
public void delete(long id, String operator) {
Cluster cluster = clusterRepository.findById(id).orElse(null);
if (cluster == null) {
throw new BadRequestException("cluster not exist");
throw BadRequestException.clusterNotExists("");
}

//delete linked namespaces
Expand Down Expand Up @@ -151,7 +151,7 @@ public void createDefaultCluster(String appId, String createBy) {
public List<Cluster> findChildClusters(String appId, String parentClusterName) {
Cluster parentCluster = findOne(appId, parentClusterName);
if (parentCluster == null) {
throw new BadRequestException("parent cluster not exist");
throw BadRequestException.clusterNotExists(parentClusterName);
}

return clusterRepository.findByParentClusterId(parentCluster.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,7 @@ private Namespace findNamespaceByAppIdAndClusterNameAndNamespaceName(String appI
String namespaceName) {
Namespace namespace = namespaceService.findOne(appId, clusterName, namespaceName);
if (namespace == null) {
throw new NotFoundException("namespace not found for appId:%s clusterName:%s namespaceName:%s",
appId, clusterName, namespaceName);
throw NotFoundException.namespaceNotFound(appId, clusterName, namespaceName);
}
return namespace;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public ItemChangeSets updateSet(String appId, String clusterName,
Namespace namespace = namespaceService.findOne(appId, clusterName, namespaceName);

if (namespace == null) {
throw new NotFoundException("Namespace %s not found", namespaceName);
throw NotFoundException.namespaceNotFound(appId, clusterName, namespaceName);
}

String operator = changeSet.getDataChangeLastModifiedBy();
Expand Down Expand Up @@ -96,7 +96,7 @@ private void doDeleteItems(List<ItemDTO> toDeleteItems, Namespace namespace, Str
for (ItemDTO item : toDeleteItems) {
Item deletedItem = itemService.delete(item.getId(), operator);
if (deletedItem.getNamespaceId() != namespace.getId()) {
throw new BadRequestException("Invalid request, item and namespace do not match!");
throw BadRequestException.namespaceNotMatch();
}

configChangeContentBuilder.deleteItem(deletedItem);
Expand All @@ -111,10 +111,10 @@ private void doUpdateItems(List<ItemDTO> toUpdateItems, Namespace namespace, Str

Item managedItem = itemService.findOne(entity.getId());
if (managedItem == null) {
throw new NotFoundException("item not found.(key=%s)", entity.getKey());
throw NotFoundException.itemNotFound(entity.getKey());
}
if (managedItem.getNamespaceId() != namespace.getId()) {
throw new BadRequestException("Invalid request, item and namespace do not match!");
throw BadRequestException.namespaceNotMatch();
}
Item beforeUpdateItem = BeanUtils.transform(Item.class, managedItem);

Expand All @@ -135,7 +135,7 @@ private void doCreateItems(List<ItemDTO> toCreateItems, Namespace namespace, Str

for (ItemDTO item : toCreateItems) {
if (item.getNamespaceId() != namespace.getId()) {
throw new BadRequestException("Invalid request, item and namespace do not match!");
throw BadRequestException.namespaceNotMatch();
}

Item entity = BeanUtils.transform(Item.class, item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ public NamespaceBranchService(
public Namespace createBranch(String appId, String parentClusterName, String namespaceName, String operator){
Namespace childNamespace = findBranch(appId, parentClusterName, namespaceName);
if (childNamespace != null){
throw new BadRequestException("namespace already has branch");
throw BadRequestException.namespaceNotExists(appId, parentClusterName, namespaceName);
}

Cluster parentCluster = clusterService.findOne(appId, parentClusterName);
if (parentCluster == null || parentCluster.getParentClusterId() != 0) {
throw new BadRequestException("cluster not exist or illegal cluster");
throw BadRequestException.clusterNotExists(parentClusterName);
}

//create child cluster
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public Page<Namespace> findByItem(String itemKey, Pageable pageable) {
public Namespace findPublicNamespaceForAssociatedNamespace(String clusterName, String namespaceName) {
AppNamespace appNamespace = appNamespaceService.findPublicNamespaceByName(namespaceName);
if (appNamespace == null) {
throw new BadRequestException("namespace not exist");
throw BadRequestException.namespaceNotExists("", clusterName, namespaceName);
}

String appId = appNamespace.getAppId();
Expand Down Expand Up @@ -392,7 +392,7 @@ public void instanceOfAppNamespaces(String appId, String clusterName, String cre
public Map<String, Boolean> namespacePublishInfo(String appId) {
List<Cluster> clusters = clusterService.findParentClusters(appId);
if (CollectionUtils.isEmpty(clusters)) {
throw new BadRequestException("app not exist");
throw BadRequestException.appNotExists(appId);
}

Map<String, Boolean> clusterHasNotPublishedItems = Maps.newHashMap();
Expand Down
Loading