All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.dgrandemange.idempotencereceiver.examples.webapp.controller.MyControllerAdvice Maven / Gradle / Ivy

The newest version!
package com.github.dgrandemange.idempotencereceiver.examples.webapp.controller;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import com.github.dgrandemange.idempotencereceiver.examples.webapp.exception.ResourceAlreadyExistsException;
import com.github.dgrandemange.idempotencereceiver.examples.webapp.exception.ResourceNotFoundException;

@ControllerAdvice
public class MyControllerAdvice {

	@ResponseBody
	@ExceptionHandler(ResourceNotFoundException.class)
	@ResponseStatus(HttpStatus.NOT_FOUND)
	String employeeNotFoundHandler(ResourceNotFoundException ex) {
		return ex.getMessage();
	}

	@ResponseBody
	@ExceptionHandler(ResourceAlreadyExistsException.class)
	@ResponseStatus(HttpStatus.CONFLICT)
	String employeeNotFoundHandler(ResourceAlreadyExistsException ex) {
		return ex.getMessage();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy