io.mosip.pmp.partner.exception.PartnerControllerAdvice Maven / Gradle / Ivy
package io.mosip.pmp.partner.exception;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
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.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
import org.springframework.web.util.ContentCachingRequestWrapper;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.mosip.pmp.partner.constant.PartnerInputExceptionConstant;
import io.mosip.pmp.partner.core.ResponseWrapper;
/**
* @author sanjeev.shrivastava
*
*/
@RestControllerAdvice
public class PartnerControllerAdvice extends ResponseEntityExceptionHandler {
@Autowired
private ObjectMapper objectMapper;
String msg = "mosip.partnermanagement";
String version = "1.0";
/**
* @param httpServletRequest
* this class contains servlet request
* @param exception
* this class contains Partner already registered exception
* @return this class contains errorCode and message
* @throws IOException
* this class contains Checked Exception
*/
@ExceptionHandler(PartnerAlreadyRegisteredException.class)
public ResponseEntity> getExcepionMassage(
final HttpServletRequest httpServletRequest, final PartnerAlreadyRegisteredException exception)
throws IOException {
ResponseWrapper responseError = setErrors(httpServletRequest);
ErrorResponse errorResponse = new ErrorResponse();
errorResponse.setErrorCode(exception.getErrorCode());
errorResponse.setMessage(exception.getErrorText());
responseError.setErrors(errorResponse);
return new ResponseEntity<>(responseError, HttpStatus.OK);
}
@ExceptionHandler(AuthenticationFailedException.class)
public ResponseEntity> getAuthenticationFailedExceptionMassage(
final HttpServletRequest httpServletRequest, final AuthenticationFailedException exception)
throws IOException {
ResponseWrapper responseError = setErrors(httpServletRequest);
ErrorResponse errorResponse = new ErrorResponse();
errorResponse.setErrorCode(exception.getErrorCode());
errorResponse.setMessage(exception.getErrorText());
responseError.setErrors(errorResponse);
return new ResponseEntity<>(responseError, HttpStatus.OK);
}
@ExceptionHandler(PartnerAlreadyRegisteredWithSamePolicyGroupException.class)
public ResponseEntity> getPartnerAlreadyRegisteredWithSamePolicyGroupExceptionMassage(
final HttpServletRequest httpServletRequest,
final PartnerAlreadyRegisteredWithSamePolicyGroupException exception) throws IOException {
ResponseWrapper responseError = setErrors(httpServletRequest);
ErrorResponse errorResponse = new ErrorResponse();
errorResponse.setErrorCode(exception.getErrorCode());
errorResponse.setMessage(exception.getErrorText());
responseError.setErrors(errorResponse);
return new ResponseEntity<>(responseError, HttpStatus.OK);
}
@Override
protected ResponseEntity
© 2015 - 2025 Weber Informatics LLC | Privacy Policy