package com.cim.idm.exception;

import com.cim.idm.utils.AjaxResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice(basePackages = {"com.zxy.idm.controller", "com.cim.idm.controller"})
public class AllExceptionHandler {

	@ResponseBody
    @ExceptionHandler(GlobalException.class) // 捕获自定义的业务异常
    public AjaxResult globalExceptionHandle(GlobalException e){
        return AjaxResult.me().setSuccess(false)
                .setErrorCode(e.getErrorCode())
                .setMessage(e.getMessage());
    }
    
    
    //捕获系统异常
	@ResponseBody
	@ExceptionHandler(Exception.class)
	public AjaxResult exceptionHandle(Exception e){
	    e.printStackTrace();
	    return AjaxResult.me().setSuccess(false)
	            .setErrorCode(500)
	            .setMessage(e.getMessage() == null ? "系统异常" : e.getMessage());
	}


}