FINERACT-2000: Clean-up retryable error codes

This commit is contained in:
jmarta
2024-01-03 12:08:07 +01:00
committed by Adam Saghy
parent 2f38d284df
commit e27a0bb53f
6 changed files with 44 additions and 35 deletions
@@ -23,7 +23,6 @@ import static org.apache.http.HttpStatus.SC_BAD_REQUEST;
import static org.apache.http.HttpStatus.SC_CONFLICT;
import static org.apache.http.HttpStatus.SC_FORBIDDEN;
import static org.apache.http.HttpStatus.SC_INTERNAL_SERVER_ERROR;
import static org.apache.http.HttpStatus.SC_LOCKED;
import static org.apache.http.HttpStatus.SC_METHOD_NOT_ALLOWED;
import static org.apache.http.HttpStatus.SC_NOT_FOUND;
import static org.apache.http.HttpStatus.SC_SERVICE_UNAVAILABLE;
@@ -107,7 +106,7 @@ public class ApiGlobalErrorResponse {
return create(SC_CONFLICT, "error.msg.loan.locked", msg, msg);
}
public static ApiGlobalErrorResponse locked(String type, String identifier) {
public static ApiGlobalErrorResponse conflict(String type, String identifier) {
String details = "";
if (type == null) {
type = "unknown";
@@ -119,7 +118,7 @@ public class ApiGlobalErrorResponse {
}
String msg = "The server is currently unable to handle the request due to concurrent modification " + details
+ ", please try again";
return create(SC_LOCKED, "error.msg.platform.service." + type + ".conflict", msg, msg);
return create(SC_CONFLICT, "error.msg.platform.service." + type + ".conflict", msg, msg);
}
public static ApiGlobalErrorResponse unAuthorized(final String defaultUserMessage) {
@@ -18,7 +18,7 @@
*/
package org.apache.fineract.infrastructure.core.exceptionmapper;
import static org.apache.http.HttpStatus.SC_LOCKED;
import static org.apache.http.HttpStatus.SC_CONFLICT;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
@@ -53,8 +53,8 @@ public class ConcurrencyFailureExceptionMapper implements FineractExceptionMappe
type = "lock";
identifier = null;
}
final ApiGlobalErrorResponse dataIntegrityError = ApiGlobalErrorResponse.locked(type, identifier);
return Response.status(SC_LOCKED).entity(dataIntegrityError).type(MediaType.APPLICATION_JSON).build();
final ApiGlobalErrorResponse dataIntegrityError = ApiGlobalErrorResponse.conflict(type, identifier);
return Response.status(SC_CONFLICT).entity(dataIntegrityError).type(MediaType.APPLICATION_JSON).build();
}
@Override
@@ -19,10 +19,11 @@
package org.apache.fineract.infrastructure.core.exceptionmapper;
import static org.apache.fineract.infrastructure.core.exception.AbstractIdempotentCommandException.IDEMPOTENT_CACHE_HEADER;
import static org.apache.http.HttpStatus.SC_INTERNAL_SERVER_ERROR;
import static org.apache.http.HttpStatus.SC_OK;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.Response.Status;
import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider;
import lombok.extern.slf4j.Slf4j;
@@ -46,18 +47,18 @@ public class IdempotentCommandExceptionMapper implements FineractExceptionMapper
@Override
public Response toResponse(final AbstractIdempotentCommandException exception) {
log.warn("Processing {} request: {}", exception.getClass().getName(), exception.getMessage());
Status status = null;
Integer status = null;
if (exception instanceof IdempotentCommandProcessSucceedException pse) {
Integer statusCode = pse.getStatusCode();
status = statusCode == null ? Status.OK : Status.fromStatusCode(statusCode);
status = statusCode == null ? SC_OK : statusCode;
}
if (exception instanceof IdempotentCommandProcessUnderProcessingException) {
status = Status.CONFLICT;
status = 425;
} else if (exception instanceof IdempotentCommandProcessFailedException pfe) {
status = Status.fromStatusCode(pfe.getStatusCode());
status = pfe.getStatusCode();
}
if (status == null) {
status = Status.INTERNAL_SERVER_ERROR;
status = SC_INTERNAL_SERVER_ERROR;
}
return Response.status(status).entity(exception.getResponse()).header(IDEMPOTENT_CACHE_HEADER, "true")
.type(MediaType.APPLICATION_JSON).build();
@@ -18,7 +18,7 @@
*/
package org.apache.fineract.infrastructure.core.exceptionmapper;
import static org.apache.http.HttpStatus.SC_LOCKED;
import static org.apache.http.HttpStatus.SC_CONFLICT;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
@@ -46,12 +46,12 @@ public class OptimisticLockExceptionMapper implements FineractExceptionMapper, E
log.warn("Exception: {}, Message: {}", exception.getClass().getName(), exception.getMessage());
String type = exception.getQuery() == null ? "unknown" : "query";
String identifier = "unknown";
final ApiGlobalErrorResponse dataIntegrityError = ApiGlobalErrorResponse.locked(type, identifier);
return Response.status(SC_LOCKED).entity(dataIntegrityError).type(MediaType.APPLICATION_JSON).build();
final ApiGlobalErrorResponse dataIntegrityError = ApiGlobalErrorResponse.conflict(type, identifier);
return Response.status(SC_CONFLICT).entity(dataIntegrityError).type(MediaType.APPLICATION_JSON).build();
}
@Override
public int errorCode() {
return 4009;
return 4019;
}
}