From c54fe3bd557f406c5262709230d4b1201e7636b9 Mon Sep 17 00:00:00 2001 From: Vince Jerald Villamora Date: Wed, 2 Nov 2022 21:11:59 +0800 Subject: [PATCH] fix(webhooks): fix duplicate logging (#21) --- .../com/abavilla/fpi/bot/processor/MetaMsgEvtPcsr.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/fpi-bot-api-core/src/main/java/com/abavilla/fpi/bot/processor/MetaMsgEvtPcsr.java b/fpi-bot-api-core/src/main/java/com/abavilla/fpi/bot/processor/MetaMsgEvtPcsr.java index 9a73fcd..466f08f 100644 --- a/fpi-bot-api-core/src/main/java/com/abavilla/fpi/bot/processor/MetaMsgEvtPcsr.java +++ b/fpi-bot-api-core/src/main/java/com/abavilla/fpi/bot/processor/MetaMsgEvtPcsr.java @@ -83,14 +83,11 @@ public Uni process(MetaMsgEvtDto evt) { // process load .chain(session -> processLoadQuery(login, session, evt)) // login failures/query exceptions - .onFailure(ApiSvcEx.class).call(ex -> handleApiEx(evt, ex)) - // failures to send response to messenger - .onFailure().invoke(this::handleMsgEx) - .replaceWithVoid(); + .onFailure(ApiSvcEx.class).recoverWithUni(ex -> handleApiEx(evt, ex)); }) .onFailure(ex -> ex instanceof MongoWriteException wEx && wEx.getError().getCategory().equals(ErrorCategory.DUPLICATE_KEY)) - .invoke(throwable -> + .recoverWithNull().invoke(throwable -> Log.warn("Received duplicate mid: " + evt.getMetaMsgId()) ); }) @@ -134,7 +131,8 @@ private Uni handleApiEx(MetaMsgEvtDto evt, Throwable ex) { handleAction = sendMsgrMsg(evt, "Error occurred, please try again"); } - return handleAction.chain(() -> metaMsgrSvc.sendTypingIndicator(evt.getSender(), false).replaceWithVoid()); + return handleAction.chain(() -> metaMsgrSvc.sendTypingIndicator( + evt.getSender(), false).replaceWithVoid()); } private Uni sendMsgrMsg(MetaMsgEvtDto evt, String msg) {