From d70977abebb6068224fc567d31e1e06f8aae40c4 Mon Sep 17 00:00:00 2001 From: Anagh Hegde Date: Mon, 19 Aug 2024 13:53:26 +0530 Subject: [PATCH] chore: add logs and response when the captcha fails (#35751) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description The PR adds logs to captcha verification flow. We do not collect any information on the captcha failures and this causes issues when we are debugging captcha errors on the users machine. ## Automation /ok-to-test tags="@tag.Sanity" ### :mag: Cypress test results > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: > Commit: 80069256b6db4e9cf8f93faeedb83621c183f09d > Cypress dashboard. > Tags: `@tag.Sanity` > Spec: >
Mon, 19 Aug 2024 07:26:34 UTC ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [ ] No ## Summary by CodeRabbit - **New Features** - Enhanced error handling and logging for reCAPTCHA verification, providing better insights into potential issues. - **Bug Fixes** - Improved robustness of the verification process by capturing and logging errors at multiple points. --- .../services/ce/GoogleRecaptchaServiceCEImpl.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GoogleRecaptchaServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GoogleRecaptchaServiceCEImpl.java index c2d744eb7f..a13df2f0ed 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GoogleRecaptchaServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GoogleRecaptchaServiceCEImpl.java @@ -5,6 +5,7 @@ import com.appsmith.server.exceptions.AppsmithError; import com.appsmith.server.exceptions.AppsmithException; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.StringUtils; import org.springframework.web.reactive.function.client.WebClient; @@ -14,6 +15,7 @@ import java.time.Duration; import java.util.HashMap; import java.util.Map; +@Slf4j public class GoogleRecaptchaServiceCEImpl implements CaptchaServiceCE { private final WebClient webClient; @@ -52,11 +54,16 @@ public class GoogleRecaptchaServiceCEImpl implements CaptchaServiceCE { .queryParam("response", recaptchaResponse) .queryParam("secret", googleRecaptchaConfig.getSecretKey()) .build()) - .retrieve() - .bodyToMono(String.class) - .flatMap(stringBody -> { + .exchange() + .flatMap(response -> { + return response.bodyToMono(String.class).zipWith(Mono.just(response.statusCode())); + }) + .flatMap(tuple -> { try { - Map response = objectMapper.readValue(stringBody, HashMap.class); + Map response = objectMapper.readValue(tuple.getT1(), HashMap.class); + if (!tuple.getT2().is2xxSuccessful()) { + log.error("Failed to verify recaptcha response. Response: {}", response); + } return Mono.just(response); } catch (JsonProcessingException e) { return Mono.error(new AppsmithException(AppsmithError.JSON_PROCESSING_ERROR, e));