ErrorHandler
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Struchkov Mark 2023-03-15 21:28:54 +03:00
parent bef96bcc0d
commit 818c0e595f
Signed by: upagge
GPG Key ID: D3018BE7BA428CA6

View File

@ -0,0 +1,33 @@
package dev.struchkov.example.bot.conf;
import dev.struchkov.godfather.main.domain.content.Message;
import dev.struchkov.godfather.simple.context.service.ErrorHandler;
import dev.struchkov.godfather.simple.domain.BoxAnswer;
import dev.struchkov.godfather.telegram.simple.context.service.TelegramSending;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import static dev.struchkov.haiti.utils.Strings.escapeMarkdown;
@Slf4j
@Component
@RequiredArgsConstructor
public class ErrorTelegramHandler implements ErrorHandler {
private final AppProperty appProperty;
private final TelegramSending sending;
@Override
public void handle(Message message, Exception e) {
log.error(e.getMessage(), e);
final String errorMessage = escapeMarkdown(e.getMessage());
sending.send(
BoxAnswer.builder()
.message("Error message:\n\n" + errorMessage)
.recipientPersonId(appProperty.getTelegramId())
.build()
);
}
}