//package com.tofly.common.oauth.exception;
//
//import com.tofly.common.core.entity.ResultRespone;
//import com.tofly.common.core.util.StringUtil;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.web.bind.annotation.ControllerAdvice;
//import org.springframework.web.bind.annotation.ExceptionHandler;
//import org.springframework.web.bind.annotation.ResponseBody;
//
//import java.io.ByteArrayOutputStream;
//import java.io.PrintStream;
//import java.lang.reflect.UndeclaredThrowableException;
//
///**
// * @author Administrator
// * @date 2019/10/17  14:16
// */
//@ResponseBody
//@ControllerAdvice
//@Slf4j
//public class CommonControllerExceptionAdvice {
//    @ExceptionHandler(value = Exception.class)
//    public ResultRespone errorHandle(Exception e){
//        String ret="";
//        if(StringUtil.isEmpty(e.getMessage())){
//            if(e instanceof UndeclaredThrowableException){
//                Throwable undeclaredThrowable = ((UndeclaredThrowableException) e).getUndeclaredThrowable();
//                if(undeclaredThrowable instanceof Exception){
//                    ret = ((Exception)undeclaredThrowable).getLocalizedMessage();
//                }
//            }
//
//            if(StringUtil.isEmpty(ret)){
//                ByteArrayOutputStream out = new ByteArrayOutputStream();
//                PrintStream pout = new PrintStream(out);
//                e.printStackTrace(pout);
//                ret = new String(out.toByteArray());
//                pout.close();
//                try {
//                    out.close();
//                } catch (Exception ee) {
//                }
//            }
//        }else {
//            ret=e.getMessage();
//        }
//        if("No AuthenticationProvider found for org.springframework.security.authentication.UsernamePasswordAuthenticationToken"
//        .equals(ret)){
//            return ResultRespone.failed("密码输入错误");
//        }else {
//            return ResultRespone.failed(ret);
//        }
//    }
//}
