更改html请求异常为ajax 没有返回json,且一定抛出异常

Blade 未结 0 186

一、该问题的重现步骤是什么?

  1. 构造不存在html请求地址

    image.png

2. 请求未返回任何信息



二、分析

  1. 请求先进入@ExceptionHandler

    @ExceptionHandler({NoHandlerFoundException.class}) @ResponseStatus(HttpStatus.NOT_FOUND) public R handleError(NoHandlerFoundException e) {    log.error("404没找到请求:{}", e.getMessage());    return R.fail(ResultCode.NOT_FOUND, e.getMessage()); }

  2. 之后进入BladeErrorController

image.pngimage.png

image.png

可以看到options,只能包括STACK_TRACE或者啥也没有

image.png

导致执行上诉代码remove时发生异常,因为errorAttributes这个Map为BladeBeanMap,改map没有提供remeove方法。所以这里的rmeove会抛出异常,且前边代码限制,无法控制不进入执行remove的if


回答
  • 消灭零回复
提交回复