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

Refine problem detail when plugin is already installed #3350

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -62,7 +62,7 @@
import run.halo.app.extension.ReactiveExtensionClient;
import run.halo.app.extension.router.IListRequest.QueryListRequest;
import run.halo.app.infra.SystemVersionSupplier;
import run.halo.app.infra.exception.PluginInstallationException;
import run.halo.app.infra.exception.PluginAlreadyExistsException;
import run.halo.app.infra.exception.UnsatisfiedAttributeValueException;
import run.halo.app.infra.utils.FileUtils;
import run.halo.app.infra.utils.VersionUtils;
Expand Down Expand Up @@ -458,11 +458,7 @@ Mono<ServerResponse> install(ServerRequest request) {
plugin.getSpec().setEnabled(false);
return client.fetch(Plugin.class, plugin.getMetadata().getName())
.doOnNext(oldPlugin -> {
String pluginName = oldPlugin.getMetadata().getName();
throw new PluginInstallationException(
"Plugin [" + pluginName + "] already installed",
"problemDetail.plugin.install.alreadyInstalled",
new Object[] {pluginName});
throw new PluginAlreadyExistsException(oldPlugin.getMetadata().getName());
})
.then(client.create(plugin))
.publishOn(Schedulers.boundedElastic())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package run.halo.app.infra.exception;

import java.net.URI;
import org.springframework.web.server.ServerWebInputException;

/**
* PluginAlreadyExistsException indicates the provided plugin has already installed before.
*
* @author johnniang
*/
public class PluginAlreadyExistsException extends ServerWebInputException {

public static final String PLUGIN_ALREADY_EXISTS_TYPE =
"https://halo.run/probs/plugin-alreay-exists";

public PluginAlreadyExistsException(String pluginName) {
super("Plugin already exists.", null, null, null, new Object[] {pluginName});
setType(URI.create(PLUGIN_ALREADY_EXISTS_TYPE));
getBody().setProperty("pluginName", pluginName);
}
}
3 changes: 2 additions & 1 deletion src/main/resources/config/i18n/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ problemDetail.title.reactor.core.Exceptions.RetryExhaustedException=Retry Exhaus
problemDetail.title.run.halo.app.infra.exception.ThemeInstallationException=Theme Install Error
problemDetail.title.run.halo.app.infra.exception.ThemeUpgradeException=Theme Upgrade Error
problemDetail.title.run.halo.app.infra.exception.PluginInstallationException=Plugin Install Error
problemDetail.title.run.halo.app.infra.exception.PluginAlreadyExistsException=Plugin Already Exists Error
problemDetail.title.run.halo.app.infra.exception.DuplicateNameException=Duplicate Name Error

# Detail definitions
Expand All @@ -30,6 +31,7 @@ problemDetail.org.springframework.web.server.MethodNotAllowedException=Request m
problemDetail.run.halo.app.extension.exception.SchemaViolationException={1} of schema {0}.
problemDetail.run.halo.app.infra.exception.AttachmentAlreadyExistsException=File {0} already exists, please rename it and try again.
problemDetail.run.halo.app.infra.exception.DuplicateNameException=Duplicate name detected, please rename it and retry.
problemDetail.run.halo.app.infra.exception.PluginAlreadyExistsException=Plugin {0} already exists.

problemDetail.comment.turnedOff=The comment function has been turned off.
problemDetail.comment.systemUsersOnly=Allow only system users to comment
Expand All @@ -41,4 +43,3 @@ problemDetail.theme.version.unsatisfied.requires=The theme requires a minimum sy
problemDetail.directoryTraversal=Directory traversal detected. Base path is {0}, but real path is {1}.

problemDetail.plugin.version.unsatisfied.requires=Plugin requires a minimum system version of {0}, but the current version is {1}.
problemDetail.plugin.install.alreadyInstalled=Plugin {0} already installed.
3 changes: 2 additions & 1 deletion src/main/resources/config/i18n/messages_zh.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ problemDetail.title.run.halo.app.infra.exception.UnsatisfiedAttributeValueExcept
problemDetail.title.run.halo.app.infra.exception.PluginInstallationException=插件安装失败
problemDetail.title.run.halo.app.infra.exception.AttachmentAlreadyExistsException=附件已存在
problemDetail.title.run.halo.app.infra.exception.DuplicateNameException=名称重复
problemDetail.title.run.halo.app.infra.exception.PluginAlreadyExistsException=插件已存在

problemDetail.run.halo.app.infra.exception.AttachmentAlreadyExistsException=文件 {0} 已存在,建议更名后重试。
problemDetail.run.halo.app.infra.exception.DuplicateNameException=检测到有重复的名称,请重命名后重试。
problemDetail.run.halo.app.infra.exception.PluginAlreadyExistsException=插件 {0} 已经存。

problemDetail.plugin.version.unsatisfied.requires=插件要求一个最小的系统版本为 {0}, 但当前版本为 {1}。
problemDetail.plugin.install.alreadyInstalled=插件 {0} 已经被安装。

problemDetail.theme.version.unsatisfied.requires=主题要求一个最小的系统版本为 {0}, 但当前版本为 {1}。