Add log verbosity.

main
Paulo Gustavo Veiga 2023-11-20 08:00:09 -08:00
parent 9668823c31
commit 769968376b
1 changed files with 11 additions and 4 deletions

View File

@ -26,6 +26,7 @@ import com.wisemapping.model.User;
import com.wisemapping.rest.model.RestErrors; import com.wisemapping.rest.model.RestErrors;
import com.wisemapping.security.Utils; import com.wisemapping.security.Utils;
import com.wisemapping.service.RegistrationException; import com.wisemapping.service.RegistrationException;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -41,6 +42,7 @@ import org.springframework.web.bind.annotation.ResponseStatus;
import jakarta.servlet.ServletContext; import jakarta.servlet.ServletContext;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import java.lang.reflect.UndeclaredThrowableException; import java.lang.reflect.UndeclaredThrowableException;
import java.util.Locale; import java.util.Locale;
@ -69,18 +71,21 @@ public class BaseController {
@ExceptionHandler(ValidationException.class) @ExceptionHandler(ValidationException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST) @ResponseStatus(HttpStatus.BAD_REQUEST)
public RestErrors handleValidationErrors(@NotNull ValidationException ex) { public RestErrors handleValidationErrors(@NotNull ValidationException ex) {
logger.error(ex.getMessage(), ex);
return new RestErrors(ex.getErrors(), messageSource); return new RestErrors(ex.getErrors(), messageSource);
} }
@ExceptionHandler(JsonHttpMessageNotReadableException.class) @ExceptionHandler(JsonHttpMessageNotReadableException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST) @ResponseStatus(HttpStatus.BAD_REQUEST)
public RestErrors handleJSONErrors(@NotNull JsonHttpMessageNotReadableException ex) { public RestErrors handleJSONErrors(@NotNull JsonHttpMessageNotReadableException ex) {
logger.error(ex.getMessage(), ex);
return new RestErrors("Communication error", Severity.SEVERE); return new RestErrors("Communication error", Severity.SEVERE);
} }
@ExceptionHandler(java.lang.reflect.UndeclaredThrowableException.class) @ExceptionHandler(java.lang.reflect.UndeclaredThrowableException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST) @ResponseStatus(HttpStatus.BAD_REQUEST)
public RestErrors handleSecurityErrors(@NotNull UndeclaredThrowableException ex) { public RestErrors handleSecurityErrors(@NotNull UndeclaredThrowableException ex) {
logger.error(ex.getMessage(), ex);
final Throwable cause = ex.getCause(); final Throwable cause = ex.getCause();
RestErrors result; RestErrors result;
if (cause instanceof ClientException) { if (cause instanceof ClientException) {
@ -94,6 +99,7 @@ public class BaseController {
@ExceptionHandler(ClientException.class) @ExceptionHandler(ClientException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST) @ResponseStatus(HttpStatus.BAD_REQUEST)
public RestErrors handleClientErrors(@NotNull ClientException ex) { public RestErrors handleClientErrors(@NotNull ClientException ex) {
logger.error(ex.getMessage(), ex);
final Locale locale = LocaleContextHolder.getLocale(); final Locale locale = LocaleContextHolder.getLocale();
return new RestErrors(ex.getMessage(messageSource, locale), ex.getSeverity(), ex.getTechInfo()); return new RestErrors(ex.getMessage(messageSource, locale), ex.getSeverity(), ex.getTechInfo());
} }
@ -107,6 +113,7 @@ public class BaseController {
// "error_description": "Bad Request" // "error_description": "Bad Request"
//}, status: 400 //}, status: 400
// //
logger.error(ex.getMessage(), ex);
response.setStatus(response.getStatus()); response.setStatus(response.getStatus());
return ex; return ex;
} }
@ -115,17 +122,17 @@ public class BaseController {
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ResponseBody @ResponseBody
public RestErrors handleServerErrors(@NotNull Exception ex, @NotNull HttpServletRequest request) { public RestErrors handleServerErrors(@NotNull Exception ex, @NotNull HttpServletRequest request) {
logger.error(ex.getMessage(), ex);
final User user = Utils.getUser(false); final User user = Utils.getUser(false);
notificationService.reportJavaException(ex, user, request); notificationService.reportJavaException(ex, user, request);
logger.error(ex);
return new RestErrors(ex.getMessage(), Severity.SEVERE); return new RestErrors(ex.getMessage(), Severity.SEVERE);
} }
@ExceptionHandler(RegistrationException.class) @ExceptionHandler(RegistrationException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST) @ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody @ResponseBody
public RestErrors handleRegistrationErrors(@NotNull RegistrationException exception) { public RestErrors handleRegistrationErrors(@NotNull RegistrationException ex) {
return new RestErrors(exception, messageSource); logger.error(ex.getMessage(), ex);
return new RestErrors(ex, messageSource);
} }
} }