I finally figured out that the obvious solution with @ExceptionHandler
does indeed work but I had to add server.error.message: always
to get the exception message into the response as well!
(the default is ok as it can contain sensitive information!)
Apart from that it looks like:
@RestControllerAdvice
class ExceptionHandlers {
@ExceptionHandler
fun handleAllErrors(e: Throwable, response: HttpServletResponse) {
...
response.sendError(status, message)
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…