Initial commit
This commit is contained in:
@@ -32,6 +32,12 @@
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<!--引入security-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
@@ -1,6 +1,8 @@
|
||||
package com.atguigu.common.execption;
|
||||
package com.atguigu.common.config.execption;
|
||||
|
||||
import com.atguigu.common.result.Result;
|
||||
import com.atguigu.common.result.ResultCodeEnum;
|
||||
import org.springframework.security.access.AccessDeniedException;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
@@ -18,6 +20,12 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
||||
@ControllerAdvice
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
/**
|
||||
* 全局异常处理,执行方法
|
||||
*
|
||||
* @param e
|
||||
* @return
|
||||
*/
|
||||
@ExceptionHandler(Exception.class)
|
||||
@ResponseBody
|
||||
public Result error(Exception e) {
|
||||
@@ -25,6 +33,12 @@ public class GlobalExceptionHandler {
|
||||
return Result.fail();
|
||||
}
|
||||
|
||||
/**
|
||||
* 特定异常处理类
|
||||
*
|
||||
* @param e
|
||||
* @return
|
||||
*/
|
||||
@ExceptionHandler(ArithmeticException.class)
|
||||
@ResponseBody
|
||||
public Result error(ArithmeticException e) {
|
||||
@@ -32,10 +46,28 @@ public class GlobalExceptionHandler {
|
||||
return Result.fail().message("执行了特定异常处理");
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义异常处理类
|
||||
*
|
||||
* @param e
|
||||
* @return
|
||||
*/
|
||||
@ExceptionHandler(GuiguException.class)
|
||||
@ResponseBody
|
||||
public Result error(GuiguException e) {
|
||||
e.printStackTrace();
|
||||
return Result.fail().message(e.getMsg()).code(e.getCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* spring security异常
|
||||
*
|
||||
* @param e
|
||||
* @return
|
||||
*/
|
||||
@ExceptionHandler(AccessDeniedException.class)
|
||||
@ResponseBody
|
||||
public Result error(AccessDeniedException e) throws AccessDeniedException {
|
||||
return Result.build(null, ResultCodeEnum.PERMISSION);
|
||||
}
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
package com.atguigu.common.execption;
|
||||
package com.atguigu.common.config.execption;
|
||||
|
||||
import com.atguigu.common.result.ResultCodeEnum;
|
||||
import lombok.Data;
|
Reference in New Issue
Block a user