// Path: app/src/main/java/york/com/retrofit2rxjavademo/http/exception/ApiException.java
// public class ApiException extends Exception {
//     // 异常处理，为速度，不必要设置getter和setter
//     public int code;
//     public String message;
// 
//     public ApiException(Throwable throwable, int code) {
//         super(throwable);
//         this.code = code;
//     }
// }
// 
// 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 android.net.ParseException;
import com.google.gson.JsonParseException;
import org.apache.http.conn.ConnectTimeoutException;
import org.json.JSONException;
import java.net.ConnectException;
import java.net.SocketTimeoutException;
import retrofit2.adapter.rxjava.HttpException;
import york.com.retrofit2rxjavademo.http.exception.ApiException;
import york.com.retrofit2rxjavademo.http.exception.ErrorType;
import york.com.retrofit2rxjavademo.http.exception.ServerException;
package york.com.retrofit2rxjavademo.http;







public class ExceptionEngine {
    //对应HTTP的状态码
    private static final int UNAUTHORIZED = 401;
    private static final int FORBIDDEN = 403;
    private static final int NOT_FOUND = 404;
    private static final int REQUEST_TIMEOUT = 408;
    private static final int INTERNAL_SERVER_ERROR = 500;
    private static final int BAD_GATEWAY = 502;
    private static final int SERVICE_UNAVAILABLE = 503;
    private static final int GATEWAY_TIMEOUT = 504;

    public static ApiException handleException(Throwable e){
        ApiException ex;
        if (e instanceof HttpException){             //HTTP错误
            HttpException httpException = (HttpException) e;
// Path: app/src/main/java/york/com/retrofit2rxjavademo/http/exception/ApiException.java
// public class ApiException extends Exception {
//     // 异常处理，为速度，不必要设置getter和setter
//     public int code;
//     public String message;
// 
//     public ApiException(Throwable throwable, int code) {
//         super(throwable);
//         this.code = code;
//     }
// }
// 
// 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/http/ExceptionEngine.java
import android.net.ParseException;
import com.google.gson.JsonParseException;
import org.apache.http.conn.ConnectTimeoutException;
import org.json.JSONException;
import java.net.ConnectException;
import java.net.SocketTimeoutException;
import retrofit2.adapter.rxjava.HttpException;
import york.com.retrofit2rxjavademo.http.exception.ApiException;
import york.com.retrofit2rxjavademo.http.exception.ErrorType;
import york.com.retrofit2rxjavademo.http.exception.ServerException;

package york.com.retrofit2rxjavademo.http;







public class ExceptionEngine {
    //对应HTTP的状态码
    private static final int UNAUTHORIZED = 401;
    private static final int FORBIDDEN = 403;
    private static final int NOT_FOUND = 404;
    private static final int REQUEST_TIMEOUT = 408;
    private static final int INTERNAL_SERVER_ERROR = 500;
    private static final int BAD_GATEWAY = 502;
    private static final int SERVICE_UNAVAILABLE = 503;
    private static final int GATEWAY_TIMEOUT = 504;

    public static ApiException handleException(Throwable e){
        ApiException ex;
        if (e instanceof HttpException){             //HTTP错误
            HttpException httpException = (HttpException) e;
            ex = new ApiException(e, ErrorType.HTTP_ERROR);