34 Star 49 Fork 39

Archx / spring-agg

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
DefaultExceptionHandler.java 1.67 KB
一键复制 编辑 原始数据 按行查看 历史
Archx 提交于 2015-01-15 15:07 . 资源管理完成
package org.springagg.web.exception.handler;
import org.apache.shiro.authz.UnauthorizedException;
import org.springagg.web.bean.JsonModel;
import org.springagg.web.exception.OperationNotAllowedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.NativeWebRequest;
/**
* 异常处理器
*
* @author ArchX[archx@foxmail.com]
*/
@ControllerAdvice
public class DefaultExceptionHandler {
/**
* 没有权限异常
*
* @param request
* @param e
* @return
*/
@ExceptionHandler({ UnauthorizedException.class })
@ResponseBody
public JsonModel processUnauthenticatedException(NativeWebRequest request, UnauthorizedException e) {
JsonModel json = new JsonModel();
json.setSuccess(false);
json.setStatus("exception");
json.setMessage("没有权限 " + e.getMessage());
json.setObj(e.getClass().getName());
return json;
}
/**
* 操作不允许
*
* @param request
* @param e
* @return
*/
@ExceptionHandler({ OperationNotAllowedException.class })
@ResponseBody
public JsonModel processOperationNotAllowedException(NativeWebRequest request, OperationNotAllowedException e) {
JsonModel json = new JsonModel();
json.setSuccess(false);
json.setStatus("exception");
json.setMessage("操作不允许 " + e.getMessage());
json.setObj(e.getClass().getName());
return json;
}
}
Java
1
https://gitee.com/archx/spring-agg.git
git@gitee.com:archx/spring-agg.git
archx
spring-agg
spring-agg
master

搜索帮助