0
我定義爲一個Spring控制器以下異常處理程序:如何從用戶端的Spring response.sendError(...)檢索描述性消息?
@ExceptionHandler(Customized4ExceptionHandler.class)
public void handleCustomized4Exception(
Customized4ExceptionHandler ex,
HttpServletRequest request,
HttpServletResponse response) throws IOException {
response.sendError(HttpStatus.EXPECTATION_FAILED.value(),
"zzzzzzz");
}
當觸發錯誤,我得到用戶側以下幾點:
錯誤代碼是正確,但不顯示「zzzzzzz」描述性消息。我如何在用戶端顯示它?
我的JavaScript:
$.ajax({
type: 'GET',
url: prefix + "/throwCustomized4ExceptionHandler",
dataType: 'json',
async: true,
success: function(result) {
alert('Unexpected success !!!');
},
error: function(jqXHR, textStatus, errorThrown) {
alert(jqXHR.status + " "
+ textStatus + " "
+ errorThrown + " !");
}
});
我剛試過,但我還是不明白 「ZZZZZ」。 – JVerstry