package com.neusoft.smart.pos.framework.exception;

import com.neusoft.smart.pos.framework.constants.CommonErrorCode;
import com.neusoft.smart.pos.framework.dto.ResponseData;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author zcf
 * @date 2017-08-13 10：43
 * @description 统一异常处理类
 */
@ControllerAdvice
class GlobalExceptionHandler {

    /*
     * 统一业务异常拦截
     */
    @ResponseBody
    @ExceptionHandler(value = BusinessCommonException.class)
    public ResponseData<String> businessCommonExceptionHandler(HttpServletRequest request, BusinessCommonException exception) {
        return new ResponseData<>(exception.getCode(), exception.getMessage());
    }
    
    @ResponseBody
    @ExceptionHandler(value = Exception.class)
    public ResponseData<String> defaultErrorHandler(HttpServletRequest request, Exception e){
    	e.getMessage();
    	e.printStackTrace();
    	return new ResponseData<>(CommonErrorCode.SYS_ERROR.getCode(),
        		CommonErrorCode.SYS_ERROR.getMessage());
    }


}
