FINERACT-1971: Enhanced error logging - Attach stacktrace

This commit is contained in:
Adam Saghy
2024-02-20 08:28:27 +01:00
committed by Arnold Gálovics
parent d06b0562f1
commit 23e00ffec9
35 changed files with 39 additions and 38 deletions
@@ -39,7 +39,7 @@ public class HttpMessageNotReadableErrorController implements ExceptionMapper<Ht
public Response toResponse(HttpMessageNotReadableException exception) {
final String globalisationMessageCode = "error.msg.invalid.json.data";
final String defaultUserMessage = "The referenced JSON data is invalid, validate date format as yyyy-MM-dd or other cases like String instead of Number";
log.warn("Exception: {}, Message: {}", exception.getClass().getName(), defaultUserMessage);
log.warn("Exception occurred", exception);
final ApiParameterError error = ApiParameterError.generalError(globalisationMessageCode, defaultUserMessage);
@@ -46,7 +46,7 @@ public class AccessDeniedExceptionMapper implements ExceptionMapper<AccessDenied
// Status code 403 really reads as:
// "Authenticated - but not authorized":
final String defaultUserMessage = exception.getMessage();
log.warn("Exception: {}, Message: {}", exception.getClass().getName(), defaultUserMessage);
log.warn("Exception occurred", exception);
return Response.status(Status.FORBIDDEN).entity(ApiGlobalErrorResponse.unAuthorized(defaultUserMessage))
.type(MediaType.APPLICATION_JSON).build();
}
@@ -44,7 +44,7 @@ public class BadCredentialsExceptionMapper implements ExceptionMapper<BadCredent
@Override
public Response toResponse(@SuppressWarnings("unused") final BadCredentialsException exception) {
log.warn("Exception: {}, Message: {}", exception.getClass().getName(), exception.getMessage());
log.warn("Exception occurred", exception);
return Response.status(Status.UNAUTHORIZED).entity(ApiGlobalErrorResponse.unAuthenticated()).type(MediaType.APPLICATION_JSON)
.build();
}
@@ -36,7 +36,7 @@ public class BusinessStepExceptionMapper implements ExceptionMapper<BusinessStep
public Response toResponse(BusinessStepException exception) {
final String globalisationMessageCode = "error.msg.invalid.request.body";
final String defaultUserMessage = exception.getMessage();
log.warn("Exception: {}, Message: {}", exception.getClass().getName(), defaultUserMessage);
log.warn("Exception occurred", exception);
final ApiParameterError error = ApiParameterError.parameterError(globalisationMessageCode, defaultUserMessage, "stepName");
@@ -36,7 +36,7 @@ public class BusinessStepNotBelongsToJobExceptionMapper implements ExceptionMapp
public Response toResponse(BusinessStepNotBelongsToJobException exception) {
final String globalisationMessageCode = "error.msg.invalid.request.body";
final String defaultUserMessage = "One of the provided Business Steps does not belong to the provided Job Name.";
log.warn("Exception: {}, Message: {}", exception.getClass().getName(), defaultUserMessage);
log.warn("Exception occurred", exception);
final ApiParameterError error = ApiParameterError.generalError(globalisationMessageCode, defaultUserMessage);
@@ -43,7 +43,7 @@ public class ConcurrencyFailureExceptionMapper implements FineractExceptionMappe
@Override
public Response toResponse(final ConcurrencyFailureException exception) {
log.warn("Exception: {}, Message: {}", exception.getClass().getName(), exception.getMessage());
log.warn("Exception occurred", exception);
String type;
String identifier;
if (exception instanceof ObjectOptimisticLockingFailureException olex) {
@@ -40,9 +40,10 @@ public class DefaultExceptionMapper implements FineractExceptionMapper, Exceptio
}
@Override
public Response toResponse(RuntimeException runtimeException) {
public Response toResponse(RuntimeException exception) {
log.warn("Exception occurred", exception);
return Response.status(SC_INTERNAL_SERVER_ERROR)
.entity(Map.of("Exception", ObjectUtils.defaultIfNull(runtimeException.getMessage(), "No error message available")))
.entity(Map.of("Exception", ObjectUtils.defaultIfNull(exception.getMessage(), "No error message available")))
.type(MediaType.APPLICATION_JSON).build();
}
}
@@ -46,7 +46,7 @@ public class IdempotentCommandExceptionMapper implements FineractExceptionMapper
@Override
public Response toResponse(final AbstractIdempotentCommandException exception) {
log.warn("Processing {} request: {}", exception.getClass().getName(), exception.getMessage());
log.warn("Exception occurred", exception);
Integer status = null;
if (exception instanceof IdempotentCommandProcessSucceedException pse) {
Integer statusCode = pse.getStatusCode();
@@ -39,7 +39,7 @@ public class InvalidInstanceTypeMethodExceptionMapper implements ExceptionMapper
@Override
public Response toResponse(final InvalidInstanceTypeMethodException exception) {
log.warn("Exception: {}, Message: {}", exception.getClass().getName(), exception.getMessage());
log.warn("Exception occurred", exception);
ApiGlobalErrorResponse errorResponse = ApiGlobalErrorResponse.invalidInstanceTypeMethod(exception.getMethod());
return Response.status(Status.METHOD_NOT_ALLOWED).entity(errorResponse).type(MediaType.APPLICATION_JSON).build();
}
@@ -42,7 +42,7 @@ public class InvalidJsonExceptionMapper implements ExceptionMapper<InvalidJsonEx
public Response toResponse(@SuppressWarnings("unused") final InvalidJsonException exception) {
final String globalisationMessageCode = "error.msg.invalid.request.body";
final String defaultUserMessage = "The JSON provided in the body of the request is invalid or missing.";
log.warn("Exception: {}, Message: {}", exception.getClass().getName(), defaultUserMessage);
log.warn("Exception occurred", exception);
final ApiParameterError error = ApiParameterError.generalError(globalisationMessageCode, defaultUserMessage);
@@ -44,7 +44,7 @@ public class InvalidTenantIdentifierExceptionMapper implements ExceptionMapper<I
@Override
public Response toResponse(@SuppressWarnings("unused") final InvalidTenantIdentifierException exception) {
log.warn("Exception: {}, Message: {}", exception.getClass().getName(), exception.getMessage());
log.warn("Exception occurred", exception);
return Response.status(Status.UNAUTHORIZED).entity(ApiGlobalErrorResponse.invalidTenantIdentifier())
.type(MediaType.APPLICATION_JSON).build();
}
@@ -34,7 +34,7 @@ public class JobIsNotFoundOrNotEnabledExceptionMapper implements ExceptionMapper
@Override
public Response toResponse(JobIsNotFoundOrNotEnabledException exception) {
log.warn("Exception: {}, Message: {}", exception.getClass().getName(), exception.getMessage());
log.warn("Exception occurred", exception);
return Response.status(Response.Status.FORBIDDEN)
.entity(ApiGlobalErrorResponse.jobIsDisabled(exception.getGlobalisationMessageCode(), exception.getDefaultUserMessage()))
.type(MediaType.APPLICATION_JSON).build();
@@ -38,7 +38,7 @@ public class JsonPathExceptionMapper implements ExceptionMapper<JsonPathExceptio
public Response toResponse(JsonPathException exception) {
final String globalisationMessageCode = "error.msg.invalid.json.path";
final String defaultUserMessage = "The referenced JSON path is invalid.";
log.warn("Exception: {}, Message: {}", exception.getClass().getName(), defaultUserMessage);
log.warn("Exception occurred", exception);
final ApiParameterError error = ApiParameterError.generalError(globalisationMessageCode, defaultUserMessage);
@@ -42,7 +42,7 @@ public class JsonSyntaxExceptionMapper implements ExceptionMapper<JsonSyntaxExce
public Response toResponse(final JsonSyntaxException exception) {
final String globalisationMessageCode = "error.msg.invalid.request.body";
final String defaultUserMessage = "The JSON syntax provided in the body of the request is invalid: " + exception.getMessage();
log.warn("Exception: {}, Message: {}", exception.getClass().getName(), defaultUserMessage);
log.warn("Exception occurred", exception);
final ApiParameterError error = ApiParameterError.generalError(globalisationMessageCode, defaultUserMessage);
@@ -42,7 +42,7 @@ public class MalformedJsonExceptionMapper implements ExceptionMapper<MalformedJs
public Response toResponse(@SuppressWarnings("unused") final MalformedJsonException exception) {
final String globalisationMessageCode = "error.msg.invalid.request.body";
final String defaultUserMessage = "The JSON provided in the body of the request is invalid or missing.";
log.warn("Exception: {}, Message: {}", exception.getClass().getName(), defaultUserMessage);
log.warn("Exception occurred", exception);
final ApiParameterError error = ApiParameterError.generalError(globalisationMessageCode, defaultUserMessage);
@@ -47,7 +47,7 @@ public class NoAuthorizationExceptionMapper implements ExceptionMapper<NoAuthori
// Status code 403 really reads as:
// "Authenticated - but not authorized":
final String defaultUserMessage = exception.getMessage();
log.warn("Exception: {}, Message: {}", exception.getClass().getName(), defaultUserMessage);
log.warn("Exception occurred", exception);
return Response.status(Status.FORBIDDEN).entity(ApiGlobalErrorResponse.unAuthorized(defaultUserMessage))
.type(MediaType.APPLICATION_JSON).build();
}
@@ -22,7 +22,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.infrastructure.core.data.ApiGlobalErrorResponse;
import org.springframework.security.core.AuthenticationException;
@@ -32,9 +31,9 @@ import org.springframework.security.web.AuthenticationEntryPoint;
public class OAuth2ExceptionEntryPoint implements AuthenticationEntryPoint {
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException)
throws IOException, ServletException {
log.warn("Exception: {}, Message: {}", authException.getClass().getName(), authException.getMessage());
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception)
throws ServletException {
log.warn("Exception occurred", exception);
ApiGlobalErrorResponse errorResponse = ApiGlobalErrorResponse.unAuthenticated();
response.setContentType("application/json");
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
@@ -43,7 +43,7 @@ public class OptimisticLockExceptionMapper implements FineractExceptionMapper, E
@Override
public Response toResponse(final OptimisticLockException exception) {
log.warn("Exception: {}, Message: {}", exception.getClass().getName(), exception.getMessage());
log.warn("Exception occurred", exception);
String type = exception.getQuery() == null ? "unknown" : "query";
String identifier = "unknown";
final ApiGlobalErrorResponse dataIntegrityError = ApiGlobalErrorResponse.conflict(type, identifier);
@@ -45,7 +45,7 @@ public class PlatformApiDataValidationExceptionMapper
@Override
public Response toResponse(final PlatformApiDataValidationException exception) {
log.warn("Exception: {}, Message: {}, Errors: {}", exception.getClass().getName(), exception.getMessage(), exception.getErrors());
log.warn("Exception occurred", exception);
final ApiGlobalErrorResponse dataValidationErrorResponse = ApiGlobalErrorResponse
.badClientRequest(exception.getGlobalisationMessageCode(), exception.getDefaultUserMessage(), exception.getErrors());
@@ -44,7 +44,7 @@ public class PlatformDataIntegrityExceptionMapper implements FineractExceptionMa
@Override
public Response toResponse(final PlatformDataIntegrityException exception) {
log.warn("Exception: {}, Message: {}", exception.getClass().getName(), exception.getMessage());
log.warn("Exception occurred", exception);
final ApiGlobalErrorResponse dataIntegrityError = ApiGlobalErrorResponse.dataIntegrityError(exception.getGlobalisationMessageCode(),
exception.getDefaultUserMessage(), exception.getParameterName(), exception.getDefaultUserMessageArgs());
@@ -44,7 +44,7 @@ public class PlatformDomainRuleExceptionMapper implements FineractExceptionMappe
@Override
public Response toResponse(final AbstractPlatformDomainRuleException exception) {
log.warn("Exception: {}, Message: {}", exception.getClass().getName(), exception.getMessage());
log.warn("Exception occurred", exception);
final ApiGlobalErrorResponse notFoundErrorResponse = ApiGlobalErrorResponse.domainRuleViolation(
exception.getGlobalisationMessageCode(), exception.getDefaultUserMessage(), exception.getDefaultUserMessageArgs());
// request understood but not carried out due to it violating some
@@ -43,7 +43,7 @@ public class PlatformInternalServerExceptionMapper implements FineractExceptionM
@Override
public Response toResponse(final PlatformInternalServerException exception) {
log.warn("Exception: {}, Message: {}", exception.getClass().getName(), exception.getMessage());
log.warn("Exception occurred", exception);
final ApiGlobalErrorResponse notFoundErrorResponse = ApiGlobalErrorResponse.serverSideError(exception.getGlobalisationMessageCode(),
exception.getDefaultUserMessage(), exception.getDefaultUserMessageArgs());
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(notFoundErrorResponse).type(MediaType.APPLICATION_JSON).build();
@@ -38,7 +38,7 @@ public class PlatformRequestBodyItemLimitValidationExceptionMapper
@Override
public Response toResponse(PlatformRequestBodyItemLimitValidationException exception) {
String globalisationMessage = "error.msg.validation.request.body.item.limit.validation";
log.warn("Exception: {}, Message: {}", exception.getClass().getName(), exception.getMessage());
log.warn("Exception occurred", exception);
final ApiGlobalErrorResponse badRequestErrorResponse = ApiGlobalErrorResponse.badClientRequest(globalisationMessage,
exception.getMessage());
return Response.status(Response.Status.BAD_REQUEST).entity(badRequestErrorResponse).type(MediaType.APPLICATION_JSON).build();
@@ -45,7 +45,7 @@ public class PlatformResourceNotFoundExceptionMapper
@Override
public Response toResponse(final AbstractPlatformResourceNotFoundException exception) {
log.warn("Exception: {}, Message: {}", exception.getClass().getName(), exception.getMessage());
log.warn("Exception occurred", exception);
final ApiGlobalErrorResponse notFoundErrorResponse = ApiGlobalErrorResponse.notFound(exception.getGlobalisationMessageCode(),
exception.getDefaultUserMessage(), exception.getDefaultUserMessageArgs());
return Response.status(Status.NOT_FOUND).entity(notFoundErrorResponse).type(MediaType.APPLICATION_JSON).build();
@@ -45,7 +45,7 @@ public class PlatformServiceUnavailableExceptionMapper implements ExceptionMappe
@Override
public Response toResponse(final AbstractPlatformServiceUnavailableException exception) {
log.warn("Exception: {}, Message: {}", exception.getClass().getName(), exception.getMessage());
log.warn("Exception occurred", exception);
final ApiGlobalErrorResponse serviceUnavailableExceptionResponse = ApiGlobalErrorResponse.serviceUnavailable(
exception.getGlobalisationMessageCode(), exception.getDefaultUserMessage(), exception.getDefaultUserMessageArgs());
return Response.status(Status.SERVICE_UNAVAILABLE).entity(serviceUnavailableExceptionResponse).type(MediaType.APPLICATION_JSON)
@@ -45,7 +45,7 @@ public class RollbackTransactionNotApprovedExceptionMapper
@Override
public Response toResponse(final RollbackTransactionNotApprovedException exception) {
log.warn("Exception: {}", exception.getClass().getName());
log.warn("Exception occurred", exception);
return Response.ok().entity(new Gson().toJson(exception.getResult())).type(MediaType.APPLICATION_JSON).build();
}
@@ -42,7 +42,7 @@ public class UnAuthenticatedUserExceptionMapper implements ExceptionMapper<UnAut
@Override
public Response toResponse(@SuppressWarnings("unused") final UnAuthenticatedUserException exception) {
// Status code 401 really reads as: "Unauthenticated":
log.warn("Exception: {}, Message: {}", exception.getClass().getName(), exception.getMessage());
log.warn("Exception occurred", exception);
return Response.status(Status.UNAUTHORIZED).entity(ApiGlobalErrorResponse.unAuthenticated()).type(MediaType.APPLICATION_JSON)
.build();
}
@@ -55,7 +55,7 @@ public class UnrecognizedQueryParamExceptionMapper implements ExceptionMapper<Un
.append(parameterName) //
.append(" has an unsupported value of: ") //
.append(parameterValue);
log.warn("Exception: {}, Message: {}", exception.getClass().getName(), defaultEnglishMessage);
log.warn("Exception occurred", exception);
final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), defaultEnglishMessage.toString(),
parameterName, parameterName, parameterValue, exception.getSupportedParams());
@@ -53,7 +53,7 @@ public class UnsupportedCommandExceptionMapper implements ExceptionMapper<Unsupp
if (message != null) {
defaultEnglishMessage.append(" ").append(message);
}
log.warn("Exception: {}, Message: {}", exception.getClass().getName(), defaultEnglishMessage);
log.warn("Exception occurred", exception);
final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), defaultEnglishMessage.toString(),
exception.getUnsupportedCommandName(), exception.getUnsupportedCommandName());
@@ -55,7 +55,7 @@ public class UnsupportedParameterExceptionMapper implements FineractExceptionMap
errors.add(error);
}
log.warn("Exception: {}, Message: {}", exception.getClass().getName(), errors);
log.warn("Exception occurred", exception);
final ApiGlobalErrorResponse invalidParameterError = ApiGlobalErrorResponse
.badClientRequest("validation.msg.validation.errors.exist", "Validation errors exist.", errors);
@@ -36,7 +36,7 @@ public class ExternalAssetOwnerInitiateTransferExceptionMapper implements Except
public Response toResponse(ExternalAssetOwnerInitiateTransferException exception) {
final String globalisationMessageCode = "error.msg.external.asset.owner.initiate";
final String defaultUserMessage = exception.getMessage();
log.warn("Exception: {}, Message: {}", exception.getClass().getName(), defaultUserMessage);
log.warn("Exception occurred", exception);
final ApiParameterError error = ApiParameterError.generalError(globalisationMessageCode, defaultUserMessage);
@@ -35,7 +35,7 @@ public class LinkedAccountRequiredExceptionMapper implements FineractExceptionMa
@Override
public Response toResponse(LinkedAccountRequiredException exception) {
log.warn("Exception: {}, Message: {}", exception.getClass().getName(), exception.getMessage());
log.warn("Exception occurred", exception);
final ApiGlobalErrorResponse notFoundErrorResponse = ApiGlobalErrorResponse.domainRuleViolation(
exception.getGlobalisationMessageCode(), exception.getDefaultUserMessage(), exception.getDefaultUserMessageArgs());
// request understood but not carried out due to it violating some
@@ -36,6 +36,7 @@ public class LoanIdsHardLockedExceptionMapper implements FineractExceptionMapper
@Override
public Response toResponse(LoanIdsHardLockedException exception) {
log.warn("Exception occurred", exception);
return Response.status(HttpStatus.SC_CONFLICT)
.entity(ApiGlobalErrorResponse.loanIsLocked(exception.getLoanIdFromRequest()).toJson()).type(MediaType.APPLICATION_JSON)
.build();
@@ -36,7 +36,7 @@ public class MultiDisbursementDataRequiredExceptionMapper
@Override
public Response toResponse(MultiDisbursementDataRequiredException exception) {
log.warn("Exception: {}, Message: {}", exception.getClass().getName(), exception.getMessage());
log.warn("Exception occurred", exception);
final ApiGlobalErrorResponse notFoundErrorResponse = ApiGlobalErrorResponse.domainRuleViolation(
exception.getGlobalisationMessageCode(), exception.getDefaultUserMessage(), exception.getDefaultUserMessageArgs());
// request understood but not carried out due to it violating some
@@ -36,7 +36,7 @@ public class LoanAccountLockCannotBeOverruledExceptionMapper implements Exceptio
public Response toResponse(LoanAccountLockCannotBeOverruledException exception) {
final String globalisationMessageCode = "error.msg.invalid.request.body";
final String defaultUserMessage = exception.getMessage();
log.warn("Exception: {}, Message: {}", exception.getClass().getName(), defaultUserMessage);
log.warn("Exception occurred", exception);
final ApiParameterError error = ApiParameterError.generalError(globalisationMessageCode, defaultUserMessage);