|
15 | 15 | */
|
16 | 16 | package edu.unc.lib.dl.ui.controller;
|
17 | 17 |
|
| 18 | +import java.net.SocketException; |
| 19 | + |
18 | 20 | import javax.servlet.http.HttpServletRequest;
|
19 | 21 | import javax.servlet.http.HttpServletResponse;
|
20 | 22 |
|
|
29 | 31 | * @author bbpennel
|
30 | 32 | */
|
31 | 33 | @Controller
|
32 |
| -public class ErrorController { |
| 34 | +public class ErrorController { |
33 | 35 | private static final Logger LOG = LoggerFactory.getLogger(ErrorController.class);
|
34 |
| - |
| 36 | + |
35 | 37 | @RequestMapping("/403")
|
36 |
| - public String handle403(Model model, HttpServletRequest request, HttpServletResponse response) { |
| 38 | + public String handle403(Model model, HttpServletRequest request, HttpServletResponse response) { |
37 | 39 | response.setStatus(HttpServletResponse.SC_FORBIDDEN);
|
38 | 40 | model.addAttribute("pageSubtitle", "Error");
|
39 |
| - return "error/403"; |
40 |
| - } |
41 |
| - |
| 41 | + return "error/403"; |
| 42 | + } |
| 43 | + |
42 | 44 | @RequestMapping("/404")
|
43 |
| - public String handle404(Model model, HttpServletResponse response) { |
| 45 | + public String handle404(Model model, HttpServletResponse response) { |
44 | 46 | LOG.debug("Page not found, forwarding to 404 page");
|
45 | 47 | response.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
46 | 48 | model.addAttribute("pageSubtitle", "Page not found");
|
47 |
| - return "error/404"; |
48 |
| - } |
| 49 | + return "error/404"; |
| 50 | + } |
49 | 51 |
|
50 | 52 | @RequestMapping("/exception")
|
51 |
| - public String handleException(Model model, HttpServletRequest request, HttpServletResponse response) { |
| 53 | + public String handleException(Model model, HttpServletRequest request, HttpServletResponse response) { |
52 | 54 | response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
53 | 55 | Throwable throwable = (Throwable) request.getAttribute("javax.servlet.error.exception");
|
54 |
| - LOG.error("An uncaught exception occurred at " + request.getAttribute("javax.servlet.forward.request_uri"), throwable); |
| 56 | + |
| 57 | + if (throwable.getCause() instanceof SocketException || throwable instanceof IllegalStateException) { |
| 58 | + LOG.debug("Connection aborted for {}", request.getAttribute("javax.servlet.forward.request_uri"), throwable); |
| 59 | + } else { |
| 60 | + LOG.error("An uncaught exception occurred at " + request.getAttribute("javax.servlet.forward.request_uri"), |
| 61 | + throwable); |
| 62 | + } |
| 63 | + |
55 | 64 | model.addAttribute("pageSubtitle", "Error");
|
56 |
| - return "error/exception"; |
57 |
| - } |
| 65 | + return "error/exception"; |
| 66 | + } |
58 | 67 | }
|
0 commit comments