Добавил исключения при отправке сообщений
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
124368fcc8
commit
27f21ce24a
@ -0,0 +1,16 @@
|
|||||||
|
package dev.struchkov.godfather.telegram.main.context.exception;
|
||||||
|
|
||||||
|
public class TelegramBotException extends RuntimeException {
|
||||||
|
|
||||||
|
public TelegramBotException() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public TelegramBotException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TelegramBotException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package dev.struchkov.godfather.telegram.main.context.exception;
|
||||||
|
|
||||||
|
public class TelegramSenderException extends TelegramBotException {
|
||||||
|
|
||||||
|
public TelegramSenderException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -9,6 +9,7 @@ import dev.struchkov.godfather.simple.domain.content.send.SendFile;
|
|||||||
import dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard;
|
import dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard;
|
||||||
import dev.struchkov.godfather.telegram.main.context.BoxAnswerPayload;
|
import dev.struchkov.godfather.telegram.main.context.BoxAnswerPayload;
|
||||||
import dev.struchkov.godfather.telegram.main.context.convert.MessageMailConvert;
|
import dev.struchkov.godfather.telegram.main.context.convert.MessageMailConvert;
|
||||||
|
import dev.struchkov.godfather.telegram.main.context.exception.TelegramSenderException;
|
||||||
import dev.struchkov.godfather.telegram.simple.context.repository.SenderRepository;
|
import dev.struchkov.godfather.telegram.simple.context.repository.SenderRepository;
|
||||||
import dev.struchkov.godfather.telegram.simple.context.service.TelegramConnect;
|
import dev.struchkov.godfather.telegram.simple.context.service.TelegramConnect;
|
||||||
import dev.struchkov.godfather.telegram.simple.context.service.TelegramSending;
|
import dev.struchkov.godfather.telegram.simple.context.service.TelegramSending;
|
||||||
@ -81,7 +82,7 @@ public class TelegramSender implements TelegramSending {
|
|||||||
try {
|
try {
|
||||||
absSender.execute(deleteMessage);
|
absSender.execute(deleteMessage);
|
||||||
} catch (TelegramApiException e) {
|
} catch (TelegramApiException e) {
|
||||||
log.error(e.getMessage(), e);
|
throw new TelegramSenderException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,9 +112,9 @@ public class TelegramSender implements TelegramSending {
|
|||||||
try {
|
try {
|
||||||
absSender.execute(editMessageText);
|
absSender.execute(editMessageText);
|
||||||
} catch (TelegramApiRequestException e) {
|
} catch (TelegramApiRequestException e) {
|
||||||
log.error(e.getApiResponse());
|
throw new TelegramSenderException(e.getApiResponse(), e);
|
||||||
} catch (TelegramApiException e) {
|
} catch (TelegramApiException e) {
|
||||||
log.error(e.getMessage(), e);
|
throw new TelegramSenderException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,8 +130,7 @@ public class TelegramSender implements TelegramSending {
|
|||||||
absSender.execute(sendInvoice);
|
absSender.execute(sendInvoice);
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
} catch (TelegramApiException e) {
|
} catch (TelegramApiException e) {
|
||||||
log.error(e.getMessage(), e);
|
throw new TelegramSenderException(e.getMessage(), e);
|
||||||
return Optional.empty();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,14 +188,14 @@ public class TelegramSender implements TelegramSending {
|
|||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
} catch (TelegramApiRequestException e) {
|
} catch (TelegramApiRequestException e) {
|
||||||
log.error(e.getApiResponse());
|
|
||||||
if (ERROR_REPLACE_MESSAGE.equals(e.getApiResponse())) {
|
if (ERROR_REPLACE_MESSAGE.equals(e.getApiResponse())) {
|
||||||
return sendMessage(telegramId, preparedAnswer, preparedAnswer, saveMessageId);
|
return sendMessage(telegramId, preparedAnswer, preparedAnswer, saveMessageId);
|
||||||
|
} else {
|
||||||
|
throw new TelegramSenderException(e.getApiResponse(), e);
|
||||||
}
|
}
|
||||||
} catch (TelegramApiException e) {
|
} catch (TelegramApiException e) {
|
||||||
log.error(e.getMessage(), e);
|
throw new TelegramSenderException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
return Optional.empty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Optional<SentBox> sendMessage(@NotNull String telegramId, @NotNull BoxAnswer boxAnswer, BoxAnswer preparedAnswer, boolean saveMessageId) {
|
private Optional<SentBox> sendMessage(@NotNull String telegramId, @NotNull BoxAnswer boxAnswer, BoxAnswer preparedAnswer, boolean saveMessageId) {
|
||||||
@ -206,9 +206,9 @@ public class TelegramSender implements TelegramSending {
|
|||||||
try {
|
try {
|
||||||
execute = absSender.execute(sendMessage);
|
execute = absSender.execute(sendMessage);
|
||||||
} catch (TelegramApiRequestException e) {
|
} catch (TelegramApiRequestException e) {
|
||||||
log.error(e.getApiResponse());
|
throw new TelegramSenderException(e.getApiResponse(), e);
|
||||||
} catch (TelegramApiException e) {
|
} catch (TelegramApiException e) {
|
||||||
log.error(e.getMessage());
|
throw new TelegramSenderException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (checkNotNull(execute)) {
|
if (checkNotNull(execute)) {
|
||||||
@ -249,9 +249,9 @@ public class TelegramSender implements TelegramSending {
|
|||||||
try {
|
try {
|
||||||
execute = absSender.execute(sendPhoto);
|
execute = absSender.execute(sendPhoto);
|
||||||
} catch (TelegramApiRequestException e) {
|
} catch (TelegramApiRequestException e) {
|
||||||
log.error(e.getApiResponse());
|
throw new TelegramSenderException(e.getApiResponse(), e);
|
||||||
} catch (TelegramApiException e) {
|
} catch (TelegramApiException e) {
|
||||||
log.error(e.getMessage());
|
throw new TelegramSenderException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
if (checkNotNull(execute)) {
|
if (checkNotNull(execute)) {
|
||||||
if (checkNotNull(senderRepository)) {
|
if (checkNotNull(senderRepository)) {
|
||||||
@ -287,9 +287,9 @@ public class TelegramSender implements TelegramSending {
|
|||||||
try {
|
try {
|
||||||
execute = absSender.execute(sendDocument);
|
execute = absSender.execute(sendDocument);
|
||||||
} catch (TelegramApiRequestException e) {
|
} catch (TelegramApiRequestException e) {
|
||||||
log.error(e.getApiResponse());
|
throw new TelegramSenderException(e.getApiResponse(), e);
|
||||||
} catch (TelegramApiException e) {
|
} catch (TelegramApiException e) {
|
||||||
log.error(e.getMessage());
|
throw new TelegramSenderException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
if (checkNotNull(execute)) {
|
if (checkNotNull(execute)) {
|
||||||
if (checkNotNull(senderRepository)) {
|
if (checkNotNull(senderRepository)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user