content: package net.alanbinu.springboot2.springboot2swagger2.exception;
  
  import java.util.Date;
  
  import org.springframework.http.HttpStatus;
  import org.springframework.http.ResponseEntity;
  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;
  
  @ControllerAdvice
  public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
  	@ExceptionHandler(ResourceNotFoundException.class)
  	public ResponseEntity<?> resourceNotFoundException(ResourceNotFoundException ex, WebRequest request) {
  		ErrorDetails errorDetails = new ErrorDetails(new Date(), ex.getMessage(), request.getDescription(false));
  		return new ResponseEntity<>(errorDetails, HttpStatus.NOT_FOUND);
  	}
  
  	@ExceptionHandler(Exception.class)
  	public ResponseEntity<?> globleExcpetionHandler(Exception ex, WebRequest request) {
  		ErrorDetails errorDetails = new ErrorDetails(new Date(), ex.getMessage(), request.getDescription(false));
  		return new ResponseEntity<>(errorDetails, HttpStatus.INTERNAL_SERVER_ERROR);
  	}
  }
  