diff --git a/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/NoFoundSenderException.java b/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/NotFoundSenderException.java similarity index 72% rename from ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/NoFoundSenderException.java rename to ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/NotFoundSenderException.java index e05a262..6567ea7 100644 --- a/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/NoFoundSenderException.java +++ b/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/NotFoundSenderException.java @@ -17,6 +17,7 @@ package net.lamgc.cgj.bot.framework; +import com.google.common.base.Strings; import net.lamgc.cgj.bot.framework.message.MessageSource; /** @@ -24,7 +25,7 @@ import net.lamgc.cgj.bot.framework.message.MessageSource; *

当 {@link SenderFactory} 无法通过传入的 {@link MessageSource} 和 Id 找到对应消息源时, 将抛出本异常. * @see SenderFactory */ -public class NoFoundSenderException extends RuntimeException { +public class NotFoundSenderException extends RuntimeException { private final MessageSource source; private final long id; @@ -34,8 +35,19 @@ public class NoFoundSenderException extends RuntimeException { * @param source 传入的消息源类型. * @param id 传入的消息源 Id. */ - public NoFoundSenderException(MessageSource source, long id) { - super("Source Type: " + source + ", id: " + id); + public NotFoundSenderException(MessageSource source, long id) { + this(source, id, null); + } + + /** + * 构造异常. + * @param source 传入的消息源类型. + * @param id 传入的消息源 Id. + */ + public NotFoundSenderException(MessageSource source, long id, String message) { + super(Strings.isNullOrEmpty(message) ? + "Source Type: " + source + ", id: " + id : + message + " (" + "Source Type: " + source + ", id: " + id + ")"); this.source = source; this.id = id; } diff --git a/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/SenderFactory.java b/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/SenderFactory.java index 52445a8..f1c6564 100644 --- a/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/SenderFactory.java +++ b/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/SenderFactory.java @@ -39,8 +39,8 @@ public interface SenderFactory extends ExtensionPoint { * @param source 消息源类型. * @param id 消息源 Id. * @return 返回消息发送器, 本方法不允许返回 null. - * @throws NoFoundSenderException 当无法获取对应的消息源发送器时, 将抛出该异常. + * @throws NotFoundSenderException 当无法获取对应的消息源发送器时, 将抛出该异常. */ - MessageSender getSender(MessageSource source, long id) throws NoFoundSenderException; + MessageSender getSender(MessageSource source, long id) throws NotFoundSenderException; }