package de.champonthis.buntspecht.controller.support;

import org.springframework.http.HttpHeaders;
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 ControllerExceptionHandler extends ResponseEntityExceptionHandler {

	
	@ExceptionHandler(value = { EntityResponseStatusException.class })
	protected ResponseEntity<Object> handleResponseEntityStatusException(RuntimeException exception,
			WebRequest request) {
		EntityResponseStatusException entityResponseStatusException = (EntityResponseStatusException) exception;
		return handleExceptionInternal(exception, entityResponseStatusException.getBody(), new HttpHeaders(),
				entityResponseStatusException.getStatus(), request);
	}

}
