- * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.gnu.org/licenses/lgpl.html
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package top.continew.starter.auth.satoken.exception;
-
-import cn.dev33.satoken.exception.NotLoginException;
-import cn.dev33.satoken.exception.NotPermissionException;
-import cn.dev33.satoken.exception.NotRoleException;
-import jakarta.servlet.http.HttpServletRequest;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.http.HttpStatus;
-import org.springframework.web.bind.annotation.ExceptionHandler;
-import org.springframework.web.bind.annotation.RestControllerAdvice;
-import top.continew.starter.web.model.R;
-
-/**
- * 全局 SaToken 异常处理器
- *
- * @author Charles7c
- * @since 1.2.0
- */
-@RestControllerAdvice
-public class GlobalSaTokenExceptionHandler {
-
- private static final Logger log = LoggerFactory.getLogger(GlobalSaTokenExceptionHandler.class);
-
- /**
- * 认证异常-登录认证
- */
- @ExceptionHandler(NotLoginException.class)
- public R handleNotLoginException(NotLoginException e, HttpServletRequest request) {
- log.error("请求地址 [{}],认证失败,无法访问系统资源。", request.getRequestURI(), e);
- String errorMsg = switch (e.getType()) {
- case NotLoginException.KICK_OUT -> "您已被踢下线。";
- case NotLoginException.BE_REPLACED_MESSAGE -> "您已被顶下线。";
- default -> "您的登录状态已过期,请重新登录。";
- };
- return R.fail(HttpStatus.UNAUTHORIZED.value(), errorMsg);
- }
-
- /**
- * 认证异常-权限认证
- */
- @ExceptionHandler(NotPermissionException.class)
- public R handleNotPermissionException(NotPermissionException e, HttpServletRequest request) {
- log.error("请求地址 [{}],权限码校验失败。", request.getRequestURI(), e);
- return R.fail(HttpStatus.FORBIDDEN.value(), "没有访问权限,请联系管理员授权");
- }
-
- /**
- * 认证异常-角色认证
- */
- @ExceptionHandler(NotRoleException.class)
- public R handleNotRoleException(NotRoleException e, HttpServletRequest request) {
- log.error("请求地址 [{}],角色权限校验失败。", request.getRequestURI(), e);
- return R.fail(HttpStatus.FORBIDDEN.value(), "没有访问权限,请联系管理员授权");
- }
-}
\ No newline at end of file
diff --git a/continew-starter-core/src/main/java/top/continew/starter/core/constant/PropertiesConstants.java b/continew-starter-core/src/main/java/top/continew/starter/core/constant/PropertiesConstants.java
index 0d0f942a..e297b018 100644
--- a/continew-starter-core/src/main/java/top/continew/starter/core/constant/PropertiesConstants.java
+++ b/continew-starter-core/src/main/java/top/continew/starter/core/constant/PropertiesConstants.java
@@ -64,6 +64,11 @@ public class PropertiesConstants {
*/
public static final String WEB_CORS = WEB + StringConstants.DOT + "cors";
+ /**
+ * 响应配置
+ */
+ public static final String WEB_RESPONSE = WEB + StringConstants.DOT + "response";
+
/**
* 链路配置
*/
@@ -74,11 +79,6 @@ public class PropertiesConstants {
*/
public static final String WEB_XSS = WEB + StringConstants.DOT + "xss";
- /**
- * 国际化配置
- */
- public static final String WEB_I18N = WEB + StringConstants.DOT + "i18n";
-
/**
* 日志配置
*/
diff --git a/continew-starter-core/src/main/java/top/continew/starter/core/exception/GlobalException.java b/continew-starter-core/src/main/java/top/continew/starter/core/exception/GlobalException.java
deleted file mode 100644
index 9193bb9e..00000000
--- a/continew-starter-core/src/main/java/top/continew/starter/core/exception/GlobalException.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
- *
- * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.gnu.org/licenses/lgpl.html
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package top.continew.starter.core.exception;
-
-/**
- * 统一错误码异常
- *
- * @author Jasmine
- * @since 2.2.0
- */
-public class GlobalException extends Exception {
-
- private ResultInfoInterface resultInfo;
-
- public GlobalException() {
- }
-
- public GlobalException(ResultInfoInterface resultInfo) {
- this.resultInfo = resultInfo;
- }
-
- public ResultInfoInterface getResultInfo() {
- return this.resultInfo;
- }
-
- public void setResultInfo(ResultInfoInterface resultInfo) {
- this.resultInfo = resultInfo;
- }
-}
diff --git a/continew-starter-core/src/main/java/top/continew/starter/core/exception/GlobalResultInfoEnum.java b/continew-starter-core/src/main/java/top/continew/starter/core/exception/GlobalResultInfoEnum.java
deleted file mode 100644
index 266d5d38..00000000
--- a/continew-starter-core/src/main/java/top/continew/starter/core/exception/GlobalResultInfoEnum.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
- *
- * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.gnu.org/licenses/lgpl.html
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package top.continew.starter.core.exception;
-
-/**
- * 接口返回码 所有业务异常都要继承该接口
- *
- * @author Jasmine
- * @since 2.2.0
- */
-public enum GlobalResultInfoEnum implements ResultInfoInterface {
-
- /**
- * 操作成功
- */
- SUCCESS(200, "操作成功"),
-
- /**
- * 操作失败
- */
- FAILED(500, "操作失败");
-
- private int code;
- private String messageKey;
- private String defaultMessage;
-
- GlobalResultInfoEnum(int code, String defaultMessage) {
- this.code = code;
- this.defaultMessage = defaultMessage;
- }
-
- GlobalResultInfoEnum(int code, String messageKey, String defaultMessage) {
- this.code = code;
- this.messageKey = messageKey;
- this.defaultMessage = defaultMessage;
- }
-
- @Override
- public int getCode() {
- return this.code;
- }
-
- @Override
- public String getMessageKey() {
- return this.messageKey;
- }
-
- @Override
- public String getDefaultMessage() {
- return this.defaultMessage;
- }
-}
diff --git a/continew-starter-core/src/main/java/top/continew/starter/core/exception/ResultInfoInterface.java b/continew-starter-core/src/main/java/top/continew/starter/core/exception/ResultInfoInterface.java
deleted file mode 100644
index d943c4db..00000000
--- a/continew-starter-core/src/main/java/top/continew/starter/core/exception/ResultInfoInterface.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
- *
- * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.gnu.org/licenses/lgpl.html
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package top.continew.starter.core.exception;
-
-/**
- * 接口返回码与消息 所有业务异常都要继承该接口
- *
- * @author Jasmine
- * @since 2.2.0
- */
-public interface ResultInfoInterface {
-
- /**
- * 获取编码
- *
- * @return String
- */
- int getCode();
-
- /**
- * 国际化消息key
- *
- * @return
- */
- default String getMessageKey() {
- return "";
- }
-
- /**
- * 获取默认消息 若从国际化文件里没有获取到值,就取默认值
- *
- * @return String
- */
- String getDefaultMessage();
-}
diff --git a/continew-starter-dependencies/pom.xml b/continew-starter-dependencies/pom.xml
index 1b9de7ee..01a03148 100644
--- a/continew-starter-dependencies/pom.xml
+++ b/continew-starter-dependencies/pom.xml
@@ -43,7 +43,7 @@
- 2.4.0
+ 2.5.0-SNAPSHOT1.1.01.38.01.16.6
@@ -61,6 +61,7 @@
15.42.2.01.12.761
+ 4.0.1-boot32.9.04.5.01.5.2
@@ -261,6 +262,13 @@
${aws-s3.version}
+
+
+ com.feiniaojin
+ graceful-response
+ ${graceful-response.version}
+
+
cn.crane4j
diff --git a/continew-starter-extension/continew-starter-extension-crud/continew-starter-extension-crud-core/src/main/java/top/continew/starter/extension/crud/model/resp/BaseIdResp.java b/continew-starter-extension/continew-starter-extension-crud/continew-starter-extension-crud-core/src/main/java/top/continew/starter/extension/crud/model/resp/BaseIdResp.java
new file mode 100644
index 00000000..04a856fe
--- /dev/null
+++ b/continew-starter-extension/continew-starter-extension-crud/continew-starter-extension-crud-core/src/main/java/top/continew/starter/extension/crud/model/resp/BaseIdResp.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package top.continew.starter.extension.crud.model.resp;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+
+import java.io.Serializable;
+
+/**
+ * ID 响应信息
+ *
+ * @author Charles7c
+ * @since 2.5.0
+ */
+public class BaseIdResp implements Serializable {
+
+ /**
+ * ID
+ */
+ @Schema(description = "ID", example = "1")
+ private T id;
+
+ public T getId() {
+ return id;
+ }
+
+ public void setId(T id) {
+ this.id = id;
+ }
+
+ BaseIdResp(final T id) {
+ this.id = id;
+ }
+
+ public static BaseIdRespBuilder builder() {
+ return new BaseIdRespBuilder();
+ }
+
+ public static class BaseIdRespBuilder {
+ private T id;
+
+ BaseIdRespBuilder() {
+ }
+
+ public BaseIdRespBuilder id(final T id) {
+ this.id = id;
+ return this;
+ }
+
+ public BaseIdResp build() {
+ return new BaseIdResp(this.id);
+ }
+ }
+}
diff --git a/continew-starter-extension/continew-starter-extension-crud/continew-starter-extension-crud-mf/src/main/java/top/continew/starter/extension/crud/controller/BaseController.java b/continew-starter-extension/continew-starter-extension-crud/continew-starter-extension-crud-mf/src/main/java/top/continew/starter/extension/crud/controller/BaseController.java
index b2c66ca5..0aaa0916 100644
--- a/continew-starter-extension/continew-starter-extension-crud/continew-starter-extension-crud-mf/src/main/java/top/continew/starter/extension/crud/controller/BaseController.java
+++ b/continew-starter-extension/continew-starter-extension-crud/continew-starter-extension-crud-mf/src/main/java/top/continew/starter/extension/crud/controller/BaseController.java
@@ -19,6 +19,7 @@ package top.continew.starter.extension.crud.controller;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.text.CharSequenceUtil;
+import com.feiniaojin.gracefulresponse.api.ExcludeFromGracefulResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
@@ -29,13 +30,13 @@ import org.springframework.web.bind.annotation.*;
import top.continew.starter.core.constant.StringConstants;
import top.continew.starter.extension.crud.annotation.CrudRequestMapping;
import top.continew.starter.extension.crud.enums.Api;
+import top.continew.starter.extension.crud.model.query.PageQuery;
import top.continew.starter.extension.crud.model.query.SortQuery;
import top.continew.starter.extension.crud.model.req.BaseReq;
+import top.continew.starter.extension.crud.model.resp.BaseIdResp;
+import top.continew.starter.extension.crud.model.resp.PageResp;
import top.continew.starter.extension.crud.service.BaseService;
import top.continew.starter.extension.crud.util.ValidateGroup;
-import top.continew.starter.extension.crud.model.query.PageQuery;
-import top.continew.starter.extension.crud.model.resp.PageResp;
-import top.continew.starter.web.model.R;
import java.util.List;
@@ -65,9 +66,9 @@ public abstract class BaseController, L, D, Q,
@Operation(summary = "分页查询列表", description = "分页查询列表")
@ResponseBody
@GetMapping
- public R> page(Q query, @Validated PageQuery pageQuery) {
+ public PageResp page(Q query, @Validated PageQuery pageQuery) {
this.checkPermission(Api.LIST);
- return R.ok(baseService.page(query, pageQuery));
+ return baseService.page(query, pageQuery);
}
/**
@@ -80,9 +81,9 @@ public abstract class BaseController, L, D, Q,
@Operation(summary = "查询树列表", description = "查询树列表")
@ResponseBody
@GetMapping("/tree")
- public R>> tree(Q query, SortQuery sortQuery) {
+ public List> tree(Q query, SortQuery sortQuery) {
this.checkPermission(Api.LIST);
- return R.ok(baseService.tree(query, sortQuery, false));
+ return baseService.tree(query, sortQuery, false);
}
/**
@@ -95,9 +96,9 @@ public abstract class BaseController, L, D, Q,
@Operation(summary = "查询列表", description = "查询列表")
@ResponseBody
@GetMapping("/list")
- public R> list(Q query, SortQuery sortQuery) {
+ public List list(Q query, SortQuery sortQuery) {
this.checkPermission(Api.LIST);
- return R.ok(baseService.list(query, sortQuery));
+ return baseService.list(query, sortQuery);
}
/**
@@ -110,9 +111,9 @@ public abstract class BaseController, L, D, Q,
@Parameter(name = "id", description = "ID", example = "1", in = ParameterIn.PATH)
@ResponseBody
@GetMapping("/{id}")
- public R get(@PathVariable("id") Long id) {
+ public D get(@PathVariable("id") Long id) {
this.checkPermission(Api.LIST);
- return R.ok(baseService.get(id));
+ return baseService.get(id);
}
/**
@@ -124,9 +125,9 @@ public abstract class BaseController, L, D, Q,
@Operation(summary = "新增数据", description = "新增数据")
@ResponseBody
@PostMapping
- public R add(@Validated(ValidateGroup.Crud.Add.class) @RequestBody C req) {
+ public BaseIdResp add(@Validated(ValidateGroup.Crud.Add.class) @RequestBody C req) {
this.checkPermission(Api.ADD);
- return R.ok("新增成功", baseService.add(req));
+ return BaseIdResp.builder().id(baseService.add(req)).build();
}
/**
@@ -134,32 +135,28 @@ public abstract class BaseController, L, D, Q,
*
* @param req 修改信息
* @param id ID
- * @return /
*/
@Operation(summary = "修改数据", description = "修改数据")
@Parameter(name = "id", description = "ID", example = "1", in = ParameterIn.PATH)
@ResponseBody
@PutMapping("/{id}")
- public R update(@Validated(ValidateGroup.Crud.Update.class) @RequestBody C req, @PathVariable("id") Long id) {
+ public void update(@Validated(ValidateGroup.Crud.Update.class) @RequestBody C req, @PathVariable("id") Long id) {
this.checkPermission(Api.UPDATE);
baseService.update(req, id);
- return R.ok("修改成功");
}
/**
* 删除
*
* @param ids ID 列表
- * @return /
*/
@Operation(summary = "删除数据", description = "删除数据")
@Parameter(name = "ids", description = "ID 列表", example = "1,2", in = ParameterIn.PATH)
@ResponseBody
@DeleteMapping("/{ids}")
- public R delete(@PathVariable("ids") List ids) {
+ public void delete(@PathVariable("ids") List ids) {
this.checkPermission(Api.DELETE);
baseService.delete(ids);
- return R.ok("删除成功");
}
/**
@@ -169,6 +166,7 @@ public abstract class BaseController, L, D, Q,
* @param sortQuery 排序查询条件
* @param response 响应对象
*/
+ @ExcludeFromGracefulResponse
@Operation(summary = "导出数据", description = "导出数据")
@GetMapping("/export")
public void export(Q query, SortQuery sortQuery, HttpServletResponse response) {
diff --git a/continew-starter-extension/continew-starter-extension-crud/continew-starter-extension-crud-mp/src/main/java/top/continew/starter/extension/crud/controller/BaseController.java b/continew-starter-extension/continew-starter-extension-crud/continew-starter-extension-crud-mp/src/main/java/top/continew/starter/extension/crud/controller/BaseController.java
index 6fc31e13..cc626cd6 100644
--- a/continew-starter-extension/continew-starter-extension-crud/continew-starter-extension-crud-mp/src/main/java/top/continew/starter/extension/crud/controller/BaseController.java
+++ b/continew-starter-extension/continew-starter-extension-crud/continew-starter-extension-crud-mp/src/main/java/top/continew/starter/extension/crud/controller/BaseController.java
@@ -19,6 +19,7 @@ package top.continew.starter.extension.crud.controller;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.text.CharSequenceUtil;
+import com.feiniaojin.gracefulresponse.api.ExcludeFromGracefulResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
@@ -31,11 +32,11 @@ import top.continew.starter.extension.crud.annotation.CrudRequestMapping;
import top.continew.starter.extension.crud.enums.Api;
import top.continew.starter.extension.crud.model.query.SortQuery;
import top.continew.starter.extension.crud.model.req.BaseReq;
+import top.continew.starter.extension.crud.model.resp.BaseIdResp;
import top.continew.starter.extension.crud.util.ValidateGroup;
import top.continew.starter.extension.crud.model.query.PageQuery;
import top.continew.starter.extension.crud.model.resp.PageResp;
import top.continew.starter.extension.crud.service.BaseService;
-import top.continew.starter.web.model.R;
import java.util.List;
@@ -65,9 +66,9 @@ public abstract class BaseController, L, D, Q,
@Operation(summary = "分页查询列表", description = "分页查询列表")
@ResponseBody
@GetMapping
- public R> page(Q query, @Validated PageQuery pageQuery) {
+ public PageResp page(Q query, @Validated PageQuery pageQuery) {
this.checkPermission(Api.LIST);
- return R.ok(baseService.page(query, pageQuery));
+ return baseService.page(query, pageQuery);
}
/**
@@ -80,9 +81,9 @@ public abstract class BaseController, L, D, Q,
@Operation(summary = "查询树列表", description = "查询树列表")
@ResponseBody
@GetMapping("/tree")
- public R>> tree(Q query, SortQuery sortQuery) {
+ public List> tree(Q query, SortQuery sortQuery) {
this.checkPermission(Api.LIST);
- return R.ok(baseService.tree(query, sortQuery, false));
+ return baseService.tree(query, sortQuery, false);
}
/**
@@ -95,9 +96,9 @@ public abstract class BaseController, L, D, Q,
@Operation(summary = "查询列表", description = "查询列表")
@ResponseBody
@GetMapping("/list")
- public R> list(Q query, SortQuery sortQuery) {
+ public List list(Q query, SortQuery sortQuery) {
this.checkPermission(Api.LIST);
- return R.ok(baseService.list(query, sortQuery));
+ return baseService.list(query, sortQuery);
}
/**
@@ -110,9 +111,9 @@ public abstract class BaseController, L, D, Q,
@Parameter(name = "id", description = "ID", example = "1", in = ParameterIn.PATH)
@ResponseBody
@GetMapping("/{id}")
- public R get(@PathVariable("id") Long id) {
+ public D get(@PathVariable("id") Long id) {
this.checkPermission(Api.LIST);
- return R.ok(baseService.get(id));
+ return baseService.get(id);
}
/**
@@ -124,9 +125,9 @@ public abstract class BaseController, L, D, Q,
@Operation(summary = "新增数据", description = "新增数据")
@ResponseBody
@PostMapping
- public R add(@Validated(ValidateGroup.Crud.Add.class) @RequestBody C req) {
+ public BaseIdResp add(@Validated(ValidateGroup.Crud.Add.class) @RequestBody C req) {
this.checkPermission(Api.ADD);
- return R.ok("新增成功", baseService.add(req));
+ return BaseIdResp.builder().id(baseService.add(req)).build();
}
/**
@@ -134,32 +135,28 @@ public abstract class BaseController, L, D, Q,
*
* @param req 修改信息
* @param id ID
- * @return /
*/
@Operation(summary = "修改数据", description = "修改数据")
@Parameter(name = "id", description = "ID", example = "1", in = ParameterIn.PATH)
@ResponseBody
@PutMapping("/{id}")
- public R update(@Validated(ValidateGroup.Crud.Update.class) @RequestBody C req, @PathVariable("id") Long id) {
+ public void update(@Validated(ValidateGroup.Crud.Update.class) @RequestBody C req, @PathVariable("id") Long id) {
this.checkPermission(Api.UPDATE);
baseService.update(req, id);
- return R.ok("修改成功");
}
/**
* 删除
*
* @param ids ID 列表
- * @return /
*/
@Operation(summary = "删除数据", description = "删除数据")
@Parameter(name = "ids", description = "ID 列表", example = "1,2", in = ParameterIn.PATH)
@ResponseBody
@DeleteMapping("/{ids}")
- public R delete(@PathVariable("ids") List ids) {
+ public void delete(@PathVariable("ids") List ids) {
this.checkPermission(Api.DELETE);
baseService.delete(ids);
- return R.ok("删除成功");
}
/**
@@ -169,6 +166,7 @@ public abstract class BaseController, L, D, Q,
* @param sortQuery 排序查询条件
* @param response 响应对象
*/
+ @ExcludeFromGracefulResponse
@Operation(summary = "导出数据", description = "导出数据")
@GetMapping("/export")
public void export(Q query, SortQuery sortQuery, HttpServletResponse response) {
diff --git a/continew-starter-web/pom.xml b/continew-starter-web/pom.xml
index 3a97f379..da290899 100644
--- a/continew-starter-web/pom.xml
+++ b/continew-starter-web/pom.xml
@@ -44,6 +44,12 @@
tlog-web-spring-boot-starter
- * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.gnu.org/licenses/lgpl.html
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package top.continew.starter.web.autoconfigure.exception;
-
-import cn.hutool.core.bean.BeanUtil;
-import cn.hutool.json.JSONUtil;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import jakarta.annotation.Resource;
-import jakarta.servlet.http.HttpServletRequest;
-import jakarta.servlet.http.HttpServletResponse;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.boot.autoconfigure.web.ServerProperties;
-import org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController;
-import org.springframework.boot.autoconfigure.web.servlet.error.ErrorViewResolver;
-import org.springframework.boot.web.servlet.error.ErrorAttributes;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.MediaType;
-import org.springframework.http.ResponseEntity;
-import org.springframework.web.bind.annotation.RestController;
-import org.springframework.web.servlet.ModelAndView;
-import top.continew.starter.web.model.R;
-
-import java.io.IOException;
-import java.util.List;
-import java.util.Map;
-
-/**
- * 全局错误处理器
- *
- * @author Charles7c
- * @since 1.0.0
- */
-@RestController
-public class GlobalErrorHandler extends BasicErrorController {
-
- private static final Logger log = LoggerFactory.getLogger(GlobalErrorHandler.class);
-
- @Resource
- private ObjectMapper objectMapper;
-
- public GlobalErrorHandler(ErrorAttributes errorAttributes,
- ServerProperties serverProperties,
- List errorViewResolvers) {
- super(errorAttributes, serverProperties.getError(), errorViewResolvers);
- }
-
- @Override
- public ModelAndView errorHtml(HttpServletRequest request, HttpServletResponse response) {
- Map errorAttributeMap = super.getErrorAttributes(request, super.getErrorAttributeOptions(request, MediaType.TEXT_HTML));
- String path = (String)errorAttributeMap.get("path");
- HttpStatus status = super.getStatus(request);
- R