// Path: jbase-spring/src/main/java/com/jayqqaa12/jbase/spring/exception/BusinessException.java
// public class BusinessException extends RuntimeException {
// 
//     protected int code;
//     protected String msg;
// 
// 
//     public BusinessException(int code) {
//         this(code, LocaleKit.MSG_PREFIX + code, null);
//     }
// 
// 
//     public BusinessException(int code, String msg) {
//         super(msg);
//         this.code = code;
//         this.msg = msg;
//     }
//     
// 
//     public BusinessException(int code, String msg, Throwable e) {
// 
//         super(msg, e);
//         this.code = code;
//         this.msg = msg;
//     }
// 
//     public int getCode() {
//         return code;
//     }
// 
//     @Override
//     public String getMessage() {
// 
//         if (msg.startsWith(LocaleKit.MSG_PREFIX))
//             return LocaleKit.resolverOrGet(this.code, this.msg);
//         else return msg;
//     }
// }
// 
// Path: jbase-spring/src/main/java/com/jayqqaa12/jbase/spring/mvc/Resp.java
// @Data
// public class Resp {
//     private int code;
//      String msg;
//     private Object data;
// 
// 
//     public  Resp(){
//     }
// 
//     private Resp(int code, String msg) {
//         this.code = code;
//         this.msg = msg;
//     }
// 
//     public static Resp response(int code) {
//         return new Resp(code, LocaleKit.resolverOrGet(code, null));
//     }
// 
//     public static Resp response(int code, String msg) {
//         return new Resp(code, LocaleKit.resolverOrGet(code, msg));
//     }
// 
// 
//     public static Resp success() {
//         return   Resp.response(RespCode.SUCCESS );
//     }
// 
// 
//     public static Resp error() {
//         return   Resp.response(RespCode.SERVER_ERROR );
//     }
// 
//     public static Resp error(String msg) {
//         return new Resp(RespCode.SERVER_ERROR, LocaleKit.resolverOrGet(RespCode.SERVER_ERROR, msg));
//     }
// 
//    
// 
// 
// 
// }


import com.alibaba.fastjson.JSON;
import com.jayqqaa12.jbase.spring.exception.BusinessException;
import com.jayqqaa12.jbase.spring.mvc.Resp;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpStatus;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.web.client.DefaultResponseErrorHandler;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import java.io.IOException;
package com.jayqqaa12.jbase.spring.feign;




/**
 * 跟dubbo有冲突
 */
@Configurable
public class RestConfig {

    @Bean
    @LoadBalanced
    public RestTemplate restTemplate() {

        RestTemplate restTemplate = new RestTemplate();
        restTemplate.setErrorHandler(new CustomResponseError());
        return restTemplate;
    }



    public class CustomResponseError extends DefaultResponseErrorHandler {
        @Override
        public void handleError(ClientHttpResponse response) throws IOException {
            HttpStatus statusCode = getHttpStatusCode(response);
            switch (statusCode.series()) {
                case CLIENT_ERROR:
                    throw new HttpClientErrorException(statusCode, response.getStatusText(),
                            response.getHeaders(), getResponseBody(response), getCharset(response));
                case SERVER_ERROR:
// Path: jbase-spring/src/main/java/com/jayqqaa12/jbase/spring/exception/BusinessException.java
// public class BusinessException extends RuntimeException {
// 
//     protected int code;
//     protected String msg;
// 
// 
//     public BusinessException(int code) {
//         this(code, LocaleKit.MSG_PREFIX + code, null);
//     }
// 
// 
//     public BusinessException(int code, String msg) {
//         super(msg);
//         this.code = code;
//         this.msg = msg;
//     }
//     
// 
//     public BusinessException(int code, String msg, Throwable e) {
// 
//         super(msg, e);
//         this.code = code;
//         this.msg = msg;
//     }
// 
//     public int getCode() {
//         return code;
//     }
// 
//     @Override
//     public String getMessage() {
// 
//         if (msg.startsWith(LocaleKit.MSG_PREFIX))
//             return LocaleKit.resolverOrGet(this.code, this.msg);
//         else return msg;
//     }
// }
// 
// Path: jbase-spring/src/main/java/com/jayqqaa12/jbase/spring/mvc/Resp.java
// @Data
// public class Resp {
//     private int code;
//      String msg;
//     private Object data;
// 
// 
//     public  Resp(){
//     }
// 
//     private Resp(int code, String msg) {
//         this.code = code;
//         this.msg = msg;
//     }
// 
//     public static Resp response(int code) {
//         return new Resp(code, LocaleKit.resolverOrGet(code, null));
//     }
// 
//     public static Resp response(int code, String msg) {
//         return new Resp(code, LocaleKit.resolverOrGet(code, msg));
//     }
// 
// 
//     public static Resp success() {
//         return   Resp.response(RespCode.SUCCESS );
//     }
// 
// 
//     public static Resp error() {
//         return   Resp.response(RespCode.SERVER_ERROR );
//     }
// 
//     public static Resp error(String msg) {
//         return new Resp(RespCode.SERVER_ERROR, LocaleKit.resolverOrGet(RespCode.SERVER_ERROR, msg));
//     }
// 
//    
// 
// 
// 
// }


// Path: jbase-spring/src/main/java/com/jayqqaa12/jbase/spring/feign/RestConfig.java
import com.alibaba.fastjson.JSON;
import com.jayqqaa12.jbase.spring.exception.BusinessException;
import com.jayqqaa12.jbase.spring.mvc.Resp;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpStatus;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.web.client.DefaultResponseErrorHandler;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import java.io.IOException;

package com.jayqqaa12.jbase.spring.feign;




/**
 * 跟dubbo有冲突
 */
@Configurable
public class RestConfig {

    @Bean
    @LoadBalanced
    public RestTemplate restTemplate() {

        RestTemplate restTemplate = new RestTemplate();
        restTemplate.setErrorHandler(new CustomResponseError());
        return restTemplate;
    }



    public class CustomResponseError extends DefaultResponseErrorHandler {
        @Override
        public void handleError(ClientHttpResponse response) throws IOException {
            HttpStatus statusCode = getHttpStatusCode(response);
            switch (statusCode.series()) {
                case CLIENT_ERROR:
                    throw new HttpClientErrorException(statusCode, response.getStatusText(),
                            response.getHeaders(), getResponseBody(response), getCharset(response));
                case SERVER_ERROR:
                    Resp req = JSON.parseObject(getResponseBody(response), Resp.class);