Refactor logging for better granularity
Updated logging levels in multiple classes to differentiate between debug and trace information. Improved log messages to support parameterized logs, ensuring sensitive or variable information is handled appropriately without concatenation.
This commit is contained in:
@@ -26,12 +26,12 @@ public class FormQuery {
|
||||
stmt.setString(2, eMail);
|
||||
ResultSet resultSet = stmt.executeQuery();
|
||||
if (!resultSet.next()) {
|
||||
logger.warn("A user tried to enter an invalid code: " + verificationCode + " with email: " + eMail);
|
||||
logger.warn("A user tried to enter an invalid code: {} with email: {}", verificationCode, eMail);
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(resultSet.getInt("formId"));
|
||||
} catch (SQLException e) {
|
||||
logger.error("Failed select form query for verification code: " + verificationCode + " with e-mail " + eMail, e);
|
||||
logger.error("Failed select form query for verification code: {} with e-mail {}", verificationCode, eMail, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@ public class FormQuery {
|
||||
stmt.setInt(1, formId);
|
||||
ResultSet resultSet = stmt.executeQuery();
|
||||
if (!resultSet.next()) {
|
||||
logger.warn("Could not find form with id: " + formId);
|
||||
logger.warn("Could not find form with id: {}", formId);
|
||||
return Optional.empty();
|
||||
}
|
||||
String json = resultSet.getString("form_json");
|
||||
@@ -55,7 +55,7 @@ public class FormQuery {
|
||||
return Optional.empty();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
logger.error("Failed select form query for form with id: " + formId, e);
|
||||
logger.error("Failed select form query for form with id: {}", formId, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
@@ -87,6 +87,7 @@ public class FormQuery {
|
||||
}
|
||||
|
||||
if (formId.isEmpty()) {
|
||||
logger.trace("Unable to find form with code: {} and email {}", code, eMail);
|
||||
return new FormQueryResult(Optional.empty(), "Unable to find form for a user with this code and e-mail");
|
||||
}
|
||||
|
||||
|
||||
@@ -27,17 +27,20 @@ public class VerifyController {
|
||||
|
||||
@PostMapping("/form")
|
||||
public CompletableFuture<ResponseEntity<String>> validateEmailFromForm(@Valid @RequestBody VerificationData verificationData) {
|
||||
logger.debug(verificationData.toString());
|
||||
logger.debug("validateEmailFromForm");
|
||||
logger.trace("verificationData: {}", verificationData);
|
||||
return new FormQuery().getFormForCode(verificationData.code, verificationData.eMail).thenApply(result -> result.form()
|
||||
.map(form -> {
|
||||
try {
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(new URI("http://51.222.255.92:8001/api/contact/submitContactForm"))//TODO get uri from form
|
||||
.uri(new URI("https://forms.alttd.com:8002/api/contact/submitContactForm"))//TODO get uri from form
|
||||
.header("Content-Type", "application/json;charset=UTF-8")
|
||||
.POST(HttpRequest.BodyPublishers.ofString(form.toJsonString(), StandardCharsets.UTF_8))
|
||||
.build();
|
||||
logger.trace("request: {}", request);
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
logger.trace("response: {}", response);
|
||||
if (response.statusCode() < 200 || response.statusCode() > 200) {
|
||||
logger.error(String.format("Failed to send form to Discord. Got status code [%d], with body\n%s", response.statusCode(), response.body()));
|
||||
//TODO handle failure
|
||||
|
||||
Reference in New Issue
Block a user