package com.ifish.exception;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ifish.dto.JsonResult;
import com.ifish.enums.ResultEnum;
import com.ifish.util.ResultUtil;

/**
 * 异常处理
 * @author Administrator
 */
@ControllerAdvice
public class ExceptionHandle{

	private static Logger log = LoggerFactory.getLogger(ExceptionHandle.class);

	@ExceptionHandler(value=Exception.class)
	@ResponseBody
	public JsonResult<?> Handle(Exception e) {
		log.error("Exception:"+e.toString());
		e.printStackTrace();
		//自定义异常
		if(e instanceof IfishException){
			IfishException ifishException = (IfishException) e;
			return ResultUtil.error(ifishException.getResult());
		}
		else{
			return ResultUtil.error(ResultEnum.fail101.getKey());
		}
	}

}
