Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FINERACT-1971: Enhanced error logging - Attach stacktrace #3760

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public Response toResponse(final AccessDeniedException exception) {
// 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ public int errorCode() {
}

@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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public Response toResponse(final NoAuthorizationException exception) {
// 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
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;
Expand All @@ -32,9 +31,9 @@
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public Response toResponse(final UnrecognizedQueryParamException exception) {
.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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public Response toResponse(final UnsupportedCommandException exception) {
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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public Response toResponse(final UnsupportedParameterException exception) {

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading