Recent comments

Excepciones



 package mx.com.gnp.gmm.configurador.exception;  
 import org.springframework.http.HttpHeaders;  
 import org.springframework.http.HttpStatus;  
 import org.springframework.http.ResponseEntity;  
 import org.springframework.http.converter.HttpMessageNotReadableException;  
 import org.springframework.web.bind.annotation.ControllerAdvice;  
 import org.springframework.web.bind.annotation.ExceptionHandler;  
 import org.springframework.web.context.request.WebRequest;  
 import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;  
 import java.util.HashMap;  
 import java.util.Map;  
 @ControllerAdvice  
 public class ManejadorStatusException extends ResponseEntityExceptionHandler {  
   @ExceptionHandler({ CotizadorException.class })  
   protected ResponseEntity<Object> handleConflict(final CotizadorException ex, final WebRequest request) {  
     Map<String, Object> bodyOfResponse = new HashMap<>();  
     bodyOfResponse.put("codigoError", "Excepcion controlada");  
     return handleExceptionInternal(ex, bodyOfResponse, new HttpHeaders(), HttpStatus.CONFLICT, request);  
   }  
   @ExceptionHandler({ Exception.class })  
   protected ResponseEntity<Object> handleError(final Exception ex, final WebRequest request) {  
     Map<String, Object> bodyOfResponse = new HashMap<>();  
     bodyOfResponse.put("codigoError", "Excepcion no controlada");  
     return handleExceptionInternal(ex, bodyOfResponse, new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR,  
         request);  
   }  
   @Override  
   protected ResponseEntity<Object> handleHttpMessageNotReadable(HttpMessageNotReadableException ex, HttpHeaders headers, HttpStatus status, WebRequest request) {  
     Map<String, Object> bodyOfResponse = new HashMap<>();  
     bodyOfResponse.put("codigoError", "Malformed JSON Request");  
     //return new ResponseEntity<Object>(bodyOfResponse, new HttpHeaders(), HttpStatus.BAD_REQUEST);  
     return handleExceptionInternal(ex, bodyOfResponse, new HttpHeaders(), HttpStatus.BAD_REQUEST,  
         request);  
   }  
 }  

No hay comentarios.