Skip to content

Commit

Permalink
[MODFISTO-513] - Use correct error code for conflict exception
Browse files Browse the repository at this point in the history
  • Loading branch information
azizbekxm committed Dec 24, 2024
1 parent 11f3013 commit 8fe645c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/main/java/org/folio/rest/exception/HttpException.java
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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);
}

Expand Down

0 comments on commit 8fe645c

Please sign in to comment.