yangzongzhuan / RuoYi-Vue

:tada: (RuoYi)官方仓库 基于SpringBoot,Spring Security,JWT,Vue & Element 的前后端分离权限管理系统,同时提供了 Vue3 的版本
http://ruoyi.vip
MIT License
2.32k stars 1.28k forks source link

全局异常处理器GlobalExceptionHandler异常响应状态码一直是200 #63

Closed BenanaH closed 1 year ago

BenanaH commented 1 year ago

在使用@RestControllerAdvice的时候应该显示标记@ResponseStatus来规定状态码

BenanaH commented 1 year ago

我在此处假设抛出了一个业务异常

/**
 * 获取部门列表
 */
@PreAuthorize("@ss.hasPermi('system:dept:list')")
@GetMapping("/list")
public AjaxResult list(SysDept dept)
{
    if (1==1){
        throw new ServiceException("异常");
    }
    List<SysDept> depts = deptService.selectDeptList(dept);
    return success(depts);
}

那么当请求此接口的时候HTTP响应状态码应当为500,并且包含异常JSON响应信息

然而浏览器获得的HTTP响应状态码依然为200

image image