move code to boot data module

This commit is contained in:
Loredana
2019-05-11 09:45:08 +03:00
parent fea110846f
commit 3c72fd0487
12 changed files with 0 additions and 103 deletions

View File

@@ -0,0 +1,11 @@
package com.baeldung.jsonexception;
public class CustomException extends RuntimeException {
private static final long serialVersionUID = 1L;
public CustomException() {
super("Custom exception message.");
}
}

View File

@@ -0,0 +1,19 @@
package com.baeldung.jsonexception;
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;
@ControllerAdvice
@ResponseBody
public class ErrorHandler {
@ExceptionHandler(CustomException.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public CustomException handleCustomException(CustomException ce) {
return ce;
}
}

View File

@@ -0,0 +1,14 @@
package com.baeldung.jsonexception;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class MainController {
@GetMapping("/")
public void index() throws CustomException {
throw new CustomException();
}
}

View File

@@ -0,0 +1,19 @@
package com.baeldung.jsonexception;
import org.junit.Test;
import com.baeldung.jsonexception.CustomException;
import com.baeldung.jsonexception.MainController;
public class MainControllerIntegrationTest {
@Test(expected = CustomException.class)
public void givenIndex_thenCustomException() throws CustomException {
MainController mainController = new MainController();
mainController.index();
}
}