diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/exception/PartnerServiceResponseExceptionHandler.java b/partner/partner-management-service/src/main/java/io/mosip/pms/exception/PartnerServiceResponseExceptionHandler.java index a5ffabc973..c8434bfc95 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/exception/PartnerServiceResponseExceptionHandler.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/exception/PartnerServiceResponseExceptionHandler.java @@ -10,13 +10,18 @@ import jakarta.servlet.http.HttpServletRequest; +import org.apache.hc.core5.http.Header; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; +import org.springframework.http.HttpStatusCode; import org.springframework.http.ResponseEntity; import org.springframework.validation.FieldError; import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.web.context.request.WebRequest; +import org.springframework.web.method.annotation.HandlerMethodValidationException; import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; import org.springframework.web.util.ContentCachingRequestWrapper; @@ -46,7 +51,8 @@ public class PartnerServiceResponseExceptionHandler extends ResponseEntityExcept String msg = "mosip.partnermanagement"; String version = "1.0"; - public ResponseEntity handleMethodArgumentNotValid(MethodArgumentNotValidException ex) { + @Override + protected ResponseEntity handleHandlerMethodValidationException(HandlerMethodValidationException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) { Map body = new LinkedHashMap<>(); body.put("id", null); body.put("version", null); @@ -54,7 +60,7 @@ public ResponseEntity handleMethodArgumentNotValid(MethodArgumentNotVali body.put("response", null); body.put("responsetime", LocalDateTime.now(ZoneId.of("UTC"))); - List fieldErrors = ex.getBindingResult().getFieldErrors(); + List fieldErrors = (List) ex.getAllErrors(); FieldError fieldError = fieldErrors.get(0); ErrorResponse errorResponse = new ErrorResponse(); @@ -65,6 +71,7 @@ public ResponseEntity handleMethodArgumentNotValid(MethodArgumentNotVali body.put("errors", errors); return ResponseEntity.badRequest().body(body); } + @ExceptionHandler(MISPServiceException.class) public ResponseEntity> getExcepionMassages(