Skip to content

Commit

Permalink
Change code as per review comment
Browse files Browse the repository at this point in the history
Signed-off-by: kameshsr <[email protected]>
  • Loading branch information
kameshsr committed May 22, 2024
1 parent 8b32272 commit 0b2c01f
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -46,15 +51,16 @@ public class PartnerServiceResponseExceptionHandler extends ResponseEntityExcept
String msg = "mosip.partnermanagement";
String version = "1.0";

public ResponseEntity<Object> handleMethodArgumentNotValid(MethodArgumentNotValidException ex) {
@Override
protected ResponseEntity<Object> handleHandlerMethodValidationException(HandlerMethodValidationException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) {
Map<String, Object> body = new LinkedHashMap<>();
body.put("id", null);
body.put("version", null);
body.put("metadata", null);
body.put("response", null);
body.put("responsetime", LocalDateTime.now(ZoneId.of("UTC")));

List<FieldError> fieldErrors = ex.getBindingResult().getFieldErrors();
List<FieldError> fieldErrors = (List<FieldError>) ex.getAllErrors();
FieldError fieldError = fieldErrors.get(0);

ErrorResponse errorResponse = new ErrorResponse();
Expand All @@ -65,6 +71,7 @@ public ResponseEntity<Object> handleMethodArgumentNotValid(MethodArgumentNotVali
body.put("errors", errors);
return ResponseEntity.badRequest().body(body);
}


@ExceptionHandler(MISPServiceException.class)
public ResponseEntity<ResponseWrapper<ErrorResponse>> getExcepionMassages(
Expand Down

0 comments on commit 0b2c01f

Please sign in to comment.