我试图捕获在我的实现中抛出的异常StreamingResponseBody
,我可以看到类内部抛出异常,但是我的处理似乎有效,但是我无法获取自定义消息,我的响应代码是200
.
@GetMapping(path = "/test", produces = "application/json")
public StreamingResponseBody test(@RequestParam(value = "var1") final String test) throws IOException{
return new StreamingResponseBody() {
@Override
public void writeTo(final OutputStream outputStream) throws IOException{
try {
// Some operations..
} catch (Exception MyExceptione e) {
throw new MyException(e);
}
}
};
}
@ExceptionHandler(MyException.class)
public ResponseEntity handleMyException(MyException exception) {
return ResponseEntity.status(exception.getHttpStatus()).body(
ErrorDTO.builder()
.message(exception.getMessage())
.description(exception.getHttpStatus().getReasonPhrase())
.build());
}
我希望我的ControllerAdvice
返回一个ResponseEntity
with a Http Status
of 500.
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)