| Total Complexity | 3 |
| Total Lines | 25 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | package com.osomapps.pt; |
||
| 13 | @RestController |
||
| 14 | class CustomErrorController implements ErrorController { |
||
| 15 | |||
| 16 | private static final String PATH = "/error"; |
||
|
|
|||
| 17 | |||
| 18 | @Value("${logging.level.org.springframework.web}") |
||
| 19 | private String loggingLevel; |
||
| 20 | |||
| 21 | @Autowired |
||
| 22 | private ErrorAttributes errorAttributes; |
||
| 23 | |||
| 24 | @RequestMapping(value = PATH) |
||
| 25 | ErrorDTO error(WebRequest webRequest, HttpServletResponse response) { |
||
| 26 | // Appropriate HTTP response code (e.g. 404 or 500) is automatically set by Spring. |
||
| 27 | // Here we just define response body. |
||
| 28 | return new ErrorDTO(response.getStatus(), getErrorAttributes(webRequest, loggingLevel)); |
||
| 29 | } |
||
| 30 | |||
| 31 | @Override |
||
| 32 | public String getErrorPath() { |
||
| 33 | return PATH; |
||
| 34 | } |
||
| 35 | |||
| 36 | private Map<String, Object> getErrorAttributes(WebRequest webRequest, String loggingLevel) { |
||
| 37 | return errorAttributes.getErrorAttributes(webRequest, "DEBUG".equals(loggingLevel)); |
||
| 38 | } |
||
| 41 |