wanting to use RestControllerAdvice and in like the default response from Spring have the path. Seems like via the ExceptionHandler I can use the WebRequest. I can see the headers but unsure how to show the path. looked at the parameters but nothing in there showed the path. How can I obtain the path of the request:
@RestControllerAdvice
public class RestControllerExceptionHandler {
@Autowired
private ErrorAttributesConfig errAttrib;
@ExceptionHandler(value = {IOException.class})
@ResponseStatus(HttpStatus.BANDWIDTH_LIMIT_EXCEEDED)
public AppErrorAttributes internalServerError(Exception e, WebRequest h) {
System.out.println(h.getContextPath());
// for (Iterator<String> i = h.getParameterNames(); i.hasNext(); ) {
// System.out.println(i.next());
// }
String[] s = h.getAttributeNames(0);
for (Iterator<String> i = h.getHeaderNames(); i.hasNext();) {
System.out.println(i.next());
}
AppErrorAttributes aea = errAttrib.appErrorAttributes();
aea.setStatus(HttpStatus.BAD_REQUEST.value());
aea.setError(HttpStatus.BAD_REQUEST.getReasonPhrase());
aea.setMessage(e.getMessage());
return aea;
}