|
@@ -17,6 +17,8 @@ import org.springframework.web.servlet.NoHandlerFoundException;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.validation.ConstraintViolationException;
|
|
|
import javax.validation.ValidationException;
|
|
|
+import java.io.PrintWriter;
|
|
|
+import java.io.StringWriter;
|
|
|
|
|
|
/**
|
|
|
* 统一捕捉异常,自定义返回参数
|
|
@@ -30,7 +32,6 @@ public class ExceptionController {
|
|
|
@ResponseStatus(HttpStatus.UNAUTHORIZED)
|
|
|
@ExceptionHandler(ShiroException.class)
|
|
|
public Result handle401(ShiroException e) {
|
|
|
-// return Result.failure(5001, e.getMessage());
|
|
|
log.error("没有授权1");
|
|
|
return Result.failure(5001, "没有授权");
|
|
|
}
|
|
@@ -71,7 +72,7 @@ public class ExceptionController {
|
|
|
@ResponseStatus(HttpStatus.OK)
|
|
|
public Result runtimeExceptionHandler(HttpServletRequest request, BaseRuntimeException e) {
|
|
|
log.error(request.getRequestURI() + ":" + e.getMsg());
|
|
|
- e.printStackTrace();
|
|
|
+ printErrorMsg(e);
|
|
|
return Result.failure(e.getCode(), e.getMsg());
|
|
|
}
|
|
|
|
|
@@ -124,6 +125,18 @@ public class ExceptionController {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * by owen 2022-4-1
|
|
|
+ * 打印错误详情
|
|
|
+ * @param e
|
|
|
+ */
|
|
|
+ private void printErrorMsg(BaseRuntimeException e){
|
|
|
+ StringWriter trace=new StringWriter();
|
|
|
+ e.printStackTrace(new PrintWriter(trace));
|
|
|
+ log.error(trace);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
}
|
|
|
|