// Path: app/src/main/java/york/com/retrofit2rxjavademo/http/exception/ErrorType.java
// public interface ErrorType {
//     /**
//      * 正常
//      */
//     int SUCCESS = 0;
//     /**
//      * 未知错误
//      */
//     int UNKNOWN = 1000;
//     /**
//      * 解析错误
//      */
//     int PARSE_ERROR = 1001;
//     /**
//      * 网络错误
//      */
//     int NETWORD_ERROR = 1002;
//     /**
//      * 协议出错
//      */
//     int HTTP_ERROR = 1003;
// }
// 
// Path: app/src/main/java/york/com/retrofit2rxjavademo/http/exception/ServerException.java
// public class ServerException extends RuntimeException{
//     // 异常处理，为速度，不必要设置getter和setter
//     public int code;
//     public String message;
// 
//     public ServerException(String message, int code) {
//         super(message);
//         this.code = code;
//         this.message = message;
//     }
// }


import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.Charset;
import okhttp3.MediaType;
import okhttp3.ResponseBody;
import retrofit2.Converter;
import york.com.retrofit2rxjavademo.http.exception.ErrorType;
import york.com.retrofit2rxjavademo.http.exception.ServerException;
import static okhttp3.internal.Util.UTF_8;
package york.com.retrofit2rxjavademo.gsonconverter;







/**
 * @author YorkYu
 * @version V1.0
 * @Description:
 * @time 2017/3/7 10:30
 */
final class CustomGsonResponseBodyConverter<T> implements Converter<ResponseBody, T> {
    private final Gson gson;
    private final TypeAdapter<T> adapter;
    private final JsonParser jsonParser;

    CustomGsonResponseBodyConverter(Gson gson, TypeAdapter<T> adapter) {
        this.gson = gson;
        this.adapter = adapter;
        jsonParser = new JsonParser();
    }

    @Override
    public T convert(ResponseBody value) throws IOException {
        String response = value.string();
        JsonElement jsonElement = jsonParser.parse(response);
        int parseCode = jsonElement.getAsJsonObject().get("code").getAsInt();
        //
// Path: app/src/main/java/york/com/retrofit2rxjavademo/http/exception/ErrorType.java
// public interface ErrorType {
//     /**
//      * 正常
//      */
//     int SUCCESS = 0;
//     /**
//      * 未知错误
//      */
//     int UNKNOWN = 1000;
//     /**
//      * 解析错误
//      */
//     int PARSE_ERROR = 1001;
//     /**
//      * 网络错误
//      */
//     int NETWORD_ERROR = 1002;
//     /**
//      * 协议出错
//      */
//     int HTTP_ERROR = 1003;
// }
// 
// Path: app/src/main/java/york/com/retrofit2rxjavademo/http/exception/ServerException.java
// public class ServerException extends RuntimeException{
//     // 异常处理，为速度，不必要设置getter和setter
//     public int code;
//     public String message;
// 
//     public ServerException(String message, int code) {
//         super(message);
//         this.code = code;
//         this.message = message;
//     }
// }


// Path: app/src/main/java/york/com/retrofit2rxjavademo/gsonconverter/CustomGsonResponseBodyConverter.java
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.Charset;
import okhttp3.MediaType;
import okhttp3.ResponseBody;
import retrofit2.Converter;
import york.com.retrofit2rxjavademo.http.exception.ErrorType;
import york.com.retrofit2rxjavademo.http.exception.ServerException;
import static okhttp3.internal.Util.UTF_8;

package york.com.retrofit2rxjavademo.gsonconverter;







/**
 * @author YorkYu
 * @version V1.0
 * @Description:
 * @time 2017/3/7 10:30
 */
final class CustomGsonResponseBodyConverter<T> implements Converter<ResponseBody, T> {
    private final Gson gson;
    private final TypeAdapter<T> adapter;
    private final JsonParser jsonParser;

    CustomGsonResponseBodyConverter(Gson gson, TypeAdapter<T> adapter) {
        this.gson = gson;
        this.adapter = adapter;
        jsonParser = new JsonParser();
    }

    @Override
    public T convert(ResponseBody value) throws IOException {
        String response = value.string();
        JsonElement jsonElement = jsonParser.parse(response);
        int parseCode = jsonElement.getAsJsonObject().get("code").getAsInt();
        //
        if (parseCode != ErrorType.SUCCESS) {