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

Refactoring the message splicing of internal Exceptions #4571

Merged
merged 59 commits into from
Sep 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 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
b0bf453
refactor(apollo): Refactoring the message splicing of internal Except…
klboke Sep 15, 2022
a711012
Merge branch 'master' into exception-logs
klboke Sep 16, 2022
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 @@ -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(String.format("release not found for %s", releaseId));
throw new NotFoundException("release not found for %s", releaseId);
}
Page<InstanceConfig> instanceConfigsPage = instanceService.findActiveInstanceConfigsByReleaseKey
(release.getReleaseKey(), pageable);
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(String.format("App not exists. AppId = %s", appId));
throw new BadRequestException("App not exists. AppId = %s", appId);
}

managedApp.setName(app.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -112,7 +112,7 @@ private void doUpdateItems(List<ItemDTO> 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!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,11 +473,11 @@ public Release rollback(long releaseId, String operator) {
PageRequest page = PageRequest.of(0, 2);
List<Release> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.:
* <pre>{@code new NotFoundException("... %s ... %s ... %s", "str", 0, 0.1)}</pre>
* 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){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public ItemChangeSets resolve(long namespaceId, String configText, List<ItemDTO>
String[] newItems = configText.split(ITEM_SEPARATOR);
Set<String> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public List<ConsumerRole> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public ResponseEntity<Void> 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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public List<AppNamespace> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand All @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public List<ClusterDTO> 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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down