Commit 96438200 authored by 霍传世's avatar 霍传世

修改全局异常捕获按钮

parent 1f319db3
...@@ -18,7 +18,7 @@ public class WebConfigurer implements WebMvcConfigurer { ...@@ -18,7 +18,7 @@ public class WebConfigurer implements WebMvcConfigurer {
@Override @Override
public void addInterceptors(InterceptorRegistry registry) { public void addInterceptors(InterceptorRegistry registry) {
// 拦截所有请求,通过判断是否有 @LoginRequired 注解 决定是否需要登录 // 拦截所有请求,通过判断是否有 @LoginRequired 注解 决定是否需要登录
registry.addInterceptor(loginInterceptor).addPathPatterns("/**").excludePathPatterns("/login/signIn") registry.addInterceptor(loginInterceptor).addPathPatterns("/**").excludePathPatterns("/login/signIn","/login/testException")
.excludePathPatterns(// 允许对于网站静态资源的无授权访问 .excludePathPatterns(// 允许对于网站静态资源的无授权访问
"/", "/",
"/*.html", "/*.html",
......
...@@ -54,6 +54,19 @@ public class LoginController { ...@@ -54,6 +54,19 @@ public class LoginController {
} }
} }
// ... existing code ...
@GetMapping("/testException")
public ResponseResult testException(@RequestParam Integer num) {
if (num == 0) {
throw new RuntimeException("除数不能为零");
}
int result = 100 / num;
return ResponseResult.success("计算结果", result);
}
// ... existing code ...
@PostMapping("/signOut") @PostMapping("/signOut")
public ResponseResult logout(@RequestBody AccountVo accountVo) { public ResponseResult logout(@RequestBody AccountVo accountVo) {
// 从Redis中删除token // 从Redis中删除token
......
package com.yuda.paperstudentconfig.exception;
import com.yuda.paperstudentconfig.utils.ResponseResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@RestControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(Exception.class)
public ResponseResult handleException(Exception e) {
// 返回友好的错误信息
return ResponseResult.fail(500, "系统异常,请联系相关客服人员");
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment