package com.yxcheng.token.common.exception.handler;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.yxcheng.token.common.exception.MyBaseException;
import com.yxcheng.token.common.model.BaseJsonModel;
import com.yxcheng.token.common.model.JsonResult;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.servlet.NoHandlerFoundException;

@ControllerAdvice
public class GlobalExceptionHandler
        extends BaseGlobalExceptionHandler
{
    @ExceptionHandler({NoHandlerFoundException.class})
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public JsonResult<BaseJsonModel> handle404Error(HttpServletRequest req, HttpServletResponse rsp, Exception e)
            throws Exception
    {
        return handleError(req, rsp, e);
    }

    @ExceptionHandler({Exception.class})
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public JsonResult<BaseJsonModel> handle500Error(HttpServletRequest req, HttpServletResponse rsp, Exception e)
            throws Exception
    {
        return handleError(req, rsp, e);
    }

//    @ExceptionHandler({MyBaseException.class})
//    @ResponseStatus(HttpStatus.OK)
//    @ResponseBody
//    public JsonResult<BaseJsonModel> handleMyException(HttpServletRequest req, HttpServletResponse rsp, MyBaseException e)
//            throws Exception
//    {
//        return handleMyError(req, rsp, e);
//    }
}
