This commit is contained in:
linfeng 2023-04-17 09:41:11 +08:00
parent 7431d99684
commit e0122381b5
2 changed files with 0 additions and 129 deletions

View File

@ -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;
}
}

View File

@ -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();
}
}