From 8fe645c7049d43cf30bbb96f398da501051535b3 Mon Sep 17 00:00:00 2001 From: Azizbek Khushvakov Date: Tue, 24 Dec 2024 14:31:59 +0500 Subject: [PATCH] [MODFISTO-513] - Use correct error code for conflict exception --- src/main/java/org/folio/rest/exception/HttpException.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/folio/rest/exception/HttpException.java b/src/main/java/org/folio/rest/exception/HttpException.java index 3d3ca912..4b858aa3 100644 --- a/src/main/java/org/folio/rest/exception/HttpException.java +++ b/src/main/java/org/folio/rest/exception/HttpException.java @@ -1,11 +1,15 @@ package org.folio.rest.exception; +import static org.folio.rest.util.ErrorCodes.CONFLICT; +import static org.folio.rest.util.ErrorCodes.GENERIC_ERROR_CODE; + import org.apache.commons.lang3.StringUtils; import org.folio.rest.jaxrs.model.Error; import org.folio.rest.jaxrs.model.Errors; import org.folio.rest.jaxrs.model.Parameter; import org.folio.rest.util.ErrorCodes; +import java.util.Collections; import java.util.List; public class HttpException extends RuntimeException { @@ -17,8 +21,9 @@ public class HttpException extends RuntimeException { public HttpException(int code, String message) { super(StringUtils.isNotEmpty(message) ? message : ErrorCodes.GENERIC_ERROR_CODE.getDescription()); this.code = code; + var ec = code == 409 ? CONFLICT : GENERIC_ERROR_CODE; this.errors = new Errors() - .withErrors(List.of(new Error().withCode(ErrorCodes.GENERIC_ERROR_CODE.getCode()).withMessage(message))) + .withErrors(Collections.singletonList(new Error().withCode(ec.getCode()).withMessage(message))) .withTotalRecords(1); }