From e0122381b559057e31a38b77e104a370c52ba89c Mon Sep 17 00:00:00 2001 From: linfeng <2445465217@qq.com> Date: Mon, 17 Apr 2023 09:41:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/exception/LinfengException.java | 63 ------------------ .../exception/LinfengExceptionHandler.java | 66 ------------------- 2 files changed, 129 deletions(-) delete mode 100644 src/main/java/io/linfeng/common/exception/LinfengException.java delete mode 100644 src/main/java/io/linfeng/common/exception/LinfengExceptionHandler.java diff --git a/src/main/java/io/linfeng/common/exception/LinfengException.java b/src/main/java/io/linfeng/common/exception/LinfengException.java deleted file mode 100644 index acfcd57..0000000 --- a/src/main/java/io/linfeng/common/exception/LinfengException.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * ----------------------------------- - * 林风社交论坛开源版本请务必保留此注释头信息 - * 开源地址: https://gitee.com/virus010101/linfeng-community - * 商业版演示站点: https://www.linfeng.tech - * 商业版购买联系技术客服 QQ: 3582996245 - * 可正常分享和学习源码,不得转卖或非法牟利! - * Copyright (c) 2021-2023 linfeng all rights reserved. - * 版权所有 ,侵权必究! - * ----------------------------------- - */ -package io.linfeng.common.exception; - -/** - * 自定义异常 - * - */ -public class LinfengException extends RuntimeException { - private static final long serialVersionUID = 1L; - - private String msg; - private int code = 500; - - public LinfengException(String msg) { - super(msg); - this.msg = msg; - } - - public LinfengException(String msg, Throwable e) { - super(msg, e); - this.msg = msg; - } - - public LinfengException(String msg, int code) { - super(msg); - this.msg = msg; - this.code = code; - } - - public LinfengException(String msg, int code, Throwable e) { - super(msg, e); - this.msg = msg; - this.code = code; - } - - public String getMsg() { - return msg; - } - - public void setMsg(String msg) { - this.msg = msg; - } - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - -} diff --git a/src/main/java/io/linfeng/common/exception/LinfengExceptionHandler.java b/src/main/java/io/linfeng/common/exception/LinfengExceptionHandler.java deleted file mode 100644 index 12a837d..0000000 --- a/src/main/java/io/linfeng/common/exception/LinfengExceptionHandler.java +++ /dev/null @@ -1,66 +0,0 @@ -/** - * ----------------------------------- - * 林风社交论坛开源版本请务必保留此注释头信息 - * 开源地址: https://gitee.com/virus010101/linfeng-community - * 商业版演示站点: https://www.linfeng.tech - * 商业版购买联系技术客服 QQ: 3582996245 - * 可正常分享和学习源码,不得转卖或非法牟利! - * Copyright (c) 2021-2023 linfeng all rights reserved. - * 版权所有 ,侵权必究! - * ----------------------------------- - */ -package io.linfeng.common.exception; - -import io.linfeng.common.utils.R; -import org.apache.shiro.authz.AuthorizationException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.dao.DuplicateKeyException; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.RestControllerAdvice; -import org.springframework.web.servlet.NoHandlerFoundException; - -/** - * 异常处理器 - * - */ -@RestControllerAdvice -public class LinfengExceptionHandler { - private Logger logger = LoggerFactory.getLogger(getClass()); - - /** - * 处理自定义异常 - */ - @ExceptionHandler(LinfengException.class) - public R handleRRException(LinfengException e){ - R r = new R(); - r.put("code", e.getCode()); - r.put("msg", e.getMessage()); - - return r; - } - - @ExceptionHandler(NoHandlerFoundException.class) - public R handlerNoFoundException(Exception e) { - logger.error(e.getMessage(), e); - return R.error(404, "路径不存在,请检查路径是否正确"); - } - - @ExceptionHandler(DuplicateKeyException.class) - public R handleDuplicateKeyException(DuplicateKeyException e){ - logger.error(e.getMessage(), e); - return R.error("数据库中已存在该记录"); - } - - @ExceptionHandler(AuthorizationException.class) - public R handleAuthorizationException(AuthorizationException e){ - logger.error(e.getMessage(), e); - return R.error("没有权限,请联系管理员授权"); - } - - @ExceptionHandler(Exception.class) - public R handleException(Exception e){ - logger.error(e.getMessage(), e); - return R.error(); - } -}