// Path: app/src/main/java/com/troy/xifan/App.java
// public class App extends Application {
//     public static final String TAG = "Xifan";
//     private static App sInstance;
// 
//     private UserRes user;
// 
//     private List<Activity> mActivityList = new ArrayList<>();
// 
//     public App() {
//         sInstance = this;
//     }
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
//         registerActivityLifecycleCallbacks(mActivityLifecycleCallbacks);
//         init();
//     }
// 
//     private void init() {
//         Router.initialize(this);
// 
//         Stetho.initializeWithDefaults(this);
//         Logger.init(TAG)                 // default PRETTYLOGGER or use just init()
//                 .methodCount(1)                 // default 2
//                 .hideThreadInfo()               // default shown
//                 .logLevel(LogLevel.FULL)        // default LogLevel.FULL
//                 .methodOffset(2);            // default 0
// 
//         FIR.init(this);
//         // 初始化参数依次为 this, AppId, AppKey
//         AVOSCloud.initialize(this, Constants.AVOSCloud.APP_ID, Constants.AVOSCloud.APP_KEY);
//         AVAnalytics.enableCrashReport(this, true);
//     }
// 
//     public static App getInstance() {
//         return sInstance;
//     }
// 
//     public UserRes getUser() {
//         return user;
//     }
// 
//     public void setUser(UserRes user) {
//         this.user = user;
//     }
// 
//     private ActivityLifecycleCallbacks mActivityLifecycleCallbacks =
//             new ActivityLifecycleCallbacks() {
//                 @Override
//                 public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
//                     if (!mActivityList.contains(activity)) {
//                         mActivityList.add(activity);
//                     }
//                 }
// 
//                 @Override
//                 public void onActivityStarted(Activity activity) {
// 
//                 }
// 
//                 @Override
//                 public void onActivityResumed(Activity activity) {
// 
//                 }
// 
//                 @Override
//                 public void onActivityPaused(Activity activity) {
// 
//                 }
// 
//                 @Override
//                 public void onActivityStopped(Activity activity) {
// 
//                 }
// 
//                 @Override
//                 public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
// 
//                 }
// 
//                 @Override
//                 public void onActivityDestroyed(Activity activity) {
//                     if (mActivityList.contains(activity)) {
//                         mActivityList.remove(activity);
//                     }
//                 }
//             };
// 
//     public List<Activity> getActivityList() {
//         return mActivityList;
//     }
// 
//     public void setActivityList(List<Activity> activityList) {
//         mActivityList = activityList;
//     }
// 
//     public void cleanActivityList() {
//         for (Activity activity : mActivityList) {
//             activity.finish();
//         }
//     }
// }


import android.content.Context;
import android.text.TextUtils;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSyntaxException;
import com.orhanobut.logger.Logger;
import com.troy.xifan.App;
import com.troy.xifan.R;
import java.io.IOException;
import java.net.ConnectException;
import java.net.SocketTimeoutException;
import retrofit2.adapter.rxjava.HttpException;
package com.troy.xifan.http.exception;


/**
 * Created by chenlongfei on 2016/11/27.
 */

public class ExceptionHandle {
    //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 RANGE_NOT_SATISFIABLE = 416;
    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) {
        e.printStackTrace();
        Logger.e("http request error result:\n" + e.fillInStackTrace());
// Path: app/src/main/java/com/troy/xifan/App.java
// public class App extends Application {
//     public static final String TAG = "Xifan";
//     private static App sInstance;
// 
//     private UserRes user;
// 
//     private List<Activity> mActivityList = new ArrayList<>();
// 
//     public App() {
//         sInstance = this;
//     }
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
//         registerActivityLifecycleCallbacks(mActivityLifecycleCallbacks);
//         init();
//     }
// 
//     private void init() {
//         Router.initialize(this);
// 
//         Stetho.initializeWithDefaults(this);
//         Logger.init(TAG)                 // default PRETTYLOGGER or use just init()
//                 .methodCount(1)                 // default 2
//                 .hideThreadInfo()               // default shown
//                 .logLevel(LogLevel.FULL)        // default LogLevel.FULL
//                 .methodOffset(2);            // default 0
// 
//         FIR.init(this);
//         // 初始化参数依次为 this, AppId, AppKey
//         AVOSCloud.initialize(this, Constants.AVOSCloud.APP_ID, Constants.AVOSCloud.APP_KEY);
//         AVAnalytics.enableCrashReport(this, true);
//     }
// 
//     public static App getInstance() {
//         return sInstance;
//     }
// 
//     public UserRes getUser() {
//         return user;
//     }
// 
//     public void setUser(UserRes user) {
//         this.user = user;
//     }
// 
//     private ActivityLifecycleCallbacks mActivityLifecycleCallbacks =
//             new ActivityLifecycleCallbacks() {
//                 @Override
//                 public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
//                     if (!mActivityList.contains(activity)) {
//                         mActivityList.add(activity);
//                     }
//                 }
// 
//                 @Override
//                 public void onActivityStarted(Activity activity) {
// 
//                 }
// 
//                 @Override
//                 public void onActivityResumed(Activity activity) {
// 
//                 }
// 
//                 @Override
//                 public void onActivityPaused(Activity activity) {
// 
//                 }
// 
//                 @Override
//                 public void onActivityStopped(Activity activity) {
// 
//                 }
// 
//                 @Override
//                 public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
// 
//                 }
// 
//                 @Override
//                 public void onActivityDestroyed(Activity activity) {
//                     if (mActivityList.contains(activity)) {
//                         mActivityList.remove(activity);
//                     }
//                 }
//             };
// 
//     public List<Activity> getActivityList() {
//         return mActivityList;
//     }
// 
//     public void setActivityList(List<Activity> activityList) {
//         mActivityList = activityList;
//     }
// 
//     public void cleanActivityList() {
//         for (Activity activity : mActivityList) {
//             activity.finish();
//         }
//     }
// }


// Path: app/src/main/java/com/troy/xifan/http/exception/ExceptionHandle.java
import android.content.Context;
import android.text.TextUtils;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSyntaxException;
import com.orhanobut.logger.Logger;
import com.troy.xifan.App;
import com.troy.xifan.R;
import java.io.IOException;
import java.net.ConnectException;
import java.net.SocketTimeoutException;
import retrofit2.adapter.rxjava.HttpException;

package com.troy.xifan.http.exception;


/**
 * Created by chenlongfei on 2016/11/27.
 */

public class ExceptionHandle {
    //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 RANGE_NOT_SATISFIABLE = 416;
    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) {
        e.printStackTrace();
        Logger.e("http request error result:\n" + e.fillInStackTrace());
        Context context = App.getInstance().getApplicationContext();