content: package io.cosmos.web;
  
  import org.springframework.http.HttpStatus;
  import org.springframework.http.ResponseEntity;
  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 java.time.LocalDateTime;
  import java.util.LinkedHashMap;
  import java.util.Map;
  import java.util.NoSuchElementException;
  
  @RestControllerAdvice
  public class ExceptionAdvisor extends ResponseEntityExceptionHandler {
      //
      @ExceptionHandler(NoSuchElementException.class)
      public ResponseEntity<Object> handleNoSuchElementException(NoSuchElementException exception, WebRequest webRequest) {
          //
          Map<String, Object> body = new LinkedHashMap<>();
          body.put("timestamp", LocalDateTime.now());
          body.put("status", HttpStatus.NOT_FOUND.value());
          body.put("error", exception.getClass().getSimpleName());
          body.put("message", exception.getMessage());
          body.put("path", webRequest.getContextPath());
  
          return new ResponseEntity<>(body, HttpStatus.NOT_FOUND);
      }
  
      @ExceptionHandler(IllegalArgumentException.class)
      public ResponseEntity<Object> handleIllegalArgumentException(IllegalArgumentException exception, WebRequest webRequest) {
          //
          Map<String, Object> body = new LinkedHashMap<>();
          body.put("timestamp", LocalDateTime.now());
          body.put("status", HttpStatus.BAD_REQUEST.value());
          body.put("error", exception.getClass().getSimpleName());
          body.put("message", exception.getMessage());
          body.put("path", webRequest.getContextPath());
  
          return new ResponseEntity<>(body, HttpStatus.BAD_REQUEST);
      }
  
      @ExceptionHandler(RuntimeException.class)
      public ResponseEntity<Object> handleRuntimeException(RuntimeException exception, WebRequest webRequest) {
          //
          Map<String, Object> body = new LinkedHashMap<>();
          body.put("timestamp", LocalDateTime.now());
          body.put("status", HttpStatus.INTERNAL_SERVER_ERROR.value());
          body.put("error", exception.getClass().getSimpleName());
          body.put("message", exception.getMessage());
          body.put("path", webRequest.getContextPath());
  
          return new ResponseEntity<>(body, HttpStatus.INTERNAL_SERVER_ERROR);
      }
  }
  