Add convention based status error pages

Update `spring-boot-sample-web-mustache` to show how convention based
status error pages can be used.

See gh-2691
This commit is contained in:
Phillip Webb
2016-04-29 10:43:10 -07:00
parent 0bf025af7b
commit 6d069de79f
5 changed files with 91 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2015 the original author or authors.
* Copyright 2012-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,8 +20,10 @@ import java.util.Date;
import java.util.Map;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
@Controller
public class WelcomeController {
@@ -36,4 +38,29 @@ public class WelcomeController {
return "welcome";
}
@RequestMapping("/serviceUnavailable")
public String ServiceUnavailable() {
throw new ServiceUnavailableException();
}
@RequestMapping("/bang")
public String bang() {
throw new RuntimeException("Boom");
}
@RequestMapping("/insufficientStorage")
public String insufficientStorage() {
throw new InsufficientStorageException();
}
@ResponseStatus(HttpStatus.SERVICE_UNAVAILABLE)
private static class ServiceUnavailableException extends RuntimeException {
}
@ResponseStatus(HttpStatus.INSUFFICIENT_STORAGE)
private static class InsufficientStorageException extends RuntimeException {
}
}