package com.xunhong.erp.turbo.weixin.handler;

import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
@Order(1)
public class WeixinExceptionHandler {

	@ResponseBody
	@ExceptionHandler(WxErrorException.class)
	public Response handleWxErrorException(WxErrorException e) {
		return SingleResponse.buildFailure(HttpStatus.BAD_REQUEST.value() + "", e.getMessage());
	}
}
