package com.gic.haoban.manage.web.exception;

import com.gic.haoban.base.api.common.ShowFrontMessageException;
import com.gic.haoban.common.utils.HaobanResponse;
import com.gic.haoban.manage.web.controller.WebBaseController;
import com.gic.haoban.manage.web.errCode.HaoBanErrCode;
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 javax.servlet.http.HttpServletResponse;
import java.util.regex.Pattern;

/**
 * Created 2018/7/24.
 *
 * @author hua
 */
@ControllerAdvice
public class GlobalExceptionHandler extends WebBaseController {
    private static Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    private static final Pattern pattern = Pattern.compile("(.*: )(.*)(\\n.*)");

    @ResponseBody
    @ExceptionHandler(ShowFrontMessageException.class)
    public HaobanResponse ControllerException(HttpServletResponse response, ShowFrontMessageException ex) {
        HaobanResponse res = new HaobanResponse();
        res.setErrorCode(HaoBanErrCode.ERR_0.getCode());
        res.setMessage(ex.getMessage());
        return res;
    }
}
