Добавил ErrorHandlerService

This commit is contained in:
Struchkov Mark 2023-02-15 23:05:43 +03:00
parent d1c1783c63
commit 022fb152f7
Signed by: upagge
GPG Key ID: D3018BE7BA428CA6
2 changed files with 31 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import dev.struchkov.bot.gitlab.telegram.unit.command.EnableProjectNotify;
import dev.struchkov.bot.gitlab.telegram.unit.flow.InitSettingFlow;
import dev.struchkov.godfather.main.core.unit.TypeUnit;
import dev.struchkov.godfather.main.domain.content.Mail;
import dev.struchkov.godfather.simple.context.service.ErrorHandler;
import dev.struchkov.godfather.simple.context.service.EventHandler;
import dev.struchkov.godfather.simple.context.service.PersonSettingService;
import dev.struchkov.godfather.simple.context.service.UnitPointerService;
@ -99,6 +100,7 @@ public class TelegramBotConfig {
@Qualifier("messageExecutorService") ExecutorService executorService,
TelegramSending sending,
PersonSettingService personSettingService,
ErrorHandler errorHandler,
StorylineService<Mail> storylineService
) {
@ -107,6 +109,7 @@ public class TelegramBotConfig {
);
autoresponder.initActionUnit(TypeUnit.BACK_CMD, new RollBackCmdAction<>(storylineService));
autoresponder.setExecutorService(executorService);
autoresponder.setErrorHandler(errorHandler);
return autoresponder;
}

View File

@ -0,0 +1,28 @@
package dev.struchkov.bot.gitlab.telegram.service;
import dev.struchkov.godfather.main.domain.BoxAnswer;
import dev.struchkov.godfather.main.domain.content.Message;
import dev.struchkov.godfather.simple.context.service.ErrorHandler;
import dev.struchkov.godfather.telegram.simple.context.service.TelegramSending;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import static dev.struchkov.godfather.main.domain.BoxAnswer.boxAnswer;
@Slf4j
@Service
@RequiredArgsConstructor
public class ErrorHandlerService implements ErrorHandler {
private final TelegramSending telegramSending;
@Override
public void handle(Message message, Exception e) {
log.error(e.getMessage(), e);
final BoxAnswer boxAnswer = boxAnswer(e.getMessage());
boxAnswer.setRecipientIfNull(message.getPersonId());
telegramSending.send(boxAnswer);
}
}