package cz.muni.fi.pa165.soccermanager.configuration;

import javax.persistence.EntityNotFoundException;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration;
import org.springframework.context.annotation.Configuration;
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.NativeWebRequest;
import org.zalando.problem.Problem;
import org.zalando.problem.Status;
import org.zalando.problem.spring.web.advice.ProblemHandling;
import org.zalando.problem.spring.web.advice.security.SecurityAdviceTrait;

@ControllerAdvice
@EnableAutoConfiguration(exclude = ErrorMvcAutoConfiguration.class)
@Configuration
public class SecurityExceptionHandler implements ProblemHandling, SecurityAdviceTrait {

  @ExceptionHandler(EntityNotFoundException.class)
  public ResponseEntity<Problem> handleFoundJpa(final EntityNotFoundException ex, final NativeWebRequest request) {
    return create(Status.NOT_FOUND, ex, request);
  }
}