From d1b440fc0d9c67c30f1ac8fe4c6d409cf3c081a7 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Fri, 31 May 2019 13:15:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=B8=9A=E5=8A=A1=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C=E5=A4=B1=E8=B4=A5=E6=99=AE=E9=80=9A=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E8=B7=B3=E8=BD=AC=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/resources/templates/error/404.html | 2 -- .../main/resources/templates/error/500.html | 2 -- .../resources/templates/error/business.html | 20 +++++++++++++++++++ .../resources/templates/error/unauth.html | 2 -- .../web/exception/GlobalExceptionHandler.java | 15 ++++++++++++-- 5 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 ruoyi-admin/src/main/resources/templates/error/business.html diff --git a/ruoyi-admin/src/main/resources/templates/error/404.html b/ruoyi-admin/src/main/resources/templates/error/404.html index d7b27704d..774a58dfd 100644 --- a/ruoyi-admin/src/main/resources/templates/error/404.html +++ b/ruoyi-admin/src/main/resources/templates/error/404.html @@ -17,7 +17,5 @@ 主页 - - diff --git a/ruoyi-admin/src/main/resources/templates/error/500.html b/ruoyi-admin/src/main/resources/templates/error/500.html index 5618070ab..f59b91b93 100644 --- a/ruoyi-admin/src/main/resources/templates/error/500.html +++ b/ruoyi-admin/src/main/resources/templates/error/500.html @@ -18,7 +18,5 @@ 主页 - - diff --git a/ruoyi-admin/src/main/resources/templates/error/business.html b/ruoyi-admin/src/main/resources/templates/error/business.html new file mode 100644 index 000000000..f47cde785 --- /dev/null +++ b/ruoyi-admin/src/main/resources/templates/error/business.html @@ -0,0 +1,20 @@ + + + + + + RuoYi - 403 + + + + + +
+

操作异常!

+ +
+ [[${errorMessage}]] +
+
+ + diff --git a/ruoyi-admin/src/main/resources/templates/error/unauth.html b/ruoyi-admin/src/main/resources/templates/error/unauth.html index b662c1229..ca14e5526 100644 --- a/ruoyi-admin/src/main/resources/templates/error/unauth.html +++ b/ruoyi-admin/src/main/resources/templates/error/unauth.html @@ -18,7 +18,5 @@ 返回主页 - - diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/exception/GlobalExceptionHandler.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/exception/GlobalExceptionHandler.java index 1f01e56da..50fbed545 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/exception/GlobalExceptionHandler.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/exception/GlobalExceptionHandler.java @@ -77,10 +77,21 @@ public class GlobalExceptionHandler * 业务异常 */ @ExceptionHandler(BusinessException.class) - public AjaxResult businessException(BusinessException e) + public Object businessException(HttpServletRequest request, BusinessException e) { log.error(e.getMessage(), e); - return AjaxResult.error(e.getMessage()); + + if (ServletUtils.isAjaxRequest(request)) + { + return AjaxResult.error(e.getMessage()); + } + else + { + ModelAndView modelAndView = new ModelAndView(); + modelAndView.addObject("errorMessage", e.getMessage()); + modelAndView.setViewName("error/business"); + return modelAndView; + } } /**