// Path: app/src/main/java/com/arellomobile/github/app/GithubError.java
// public class GithubError extends Throwable {
// 	public GithubError(ResponseBody responseBody) {
// 		super(getMessage(responseBody));
// 	}
// 
// 	private static String getMessage(ResponseBody responseBody) {
// 		try {
// 			return new JSONObject(responseBody.string()).optString("message");
// 		} catch (JSONException | IOException e) {
// 			e.printStackTrace();
// 		}
// 
// 		return "Unknown exception";
// 	}
// }


import java.io.IOException;
import com.arellomobile.github.app.GithubError;
import retrofit2.Call;
import retrofit2.Response;
import rx.Observable;
import rx.Scheduler;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
package com.arellomobile.github.mvp.common;




/**
 * Date: 18.01.2016
 * Time: 14:37
 *
 * @author Yuri Shmakov
 */
public class RxUtils {
	public static <T> Observable<T> wrapRetrofitCall(final Call<T> call) {
		return Observable.create(subscriber ->
		{
			final Response<T> execute;
			try {
				execute = call.execute();
			} catch (IOException e) {
				subscriber.onError(e);
				return;
			}

			if (execute.isSuccess()) {
				subscriber.onNext(execute.body());
			} else {
// Path: app/src/main/java/com/arellomobile/github/app/GithubError.java
// public class GithubError extends Throwable {
// 	public GithubError(ResponseBody responseBody) {
// 		super(getMessage(responseBody));
// 	}
// 
// 	private static String getMessage(ResponseBody responseBody) {
// 		try {
// 			return new JSONObject(responseBody.string()).optString("message");
// 		} catch (JSONException | IOException e) {
// 			e.printStackTrace();
// 		}
// 
// 		return "Unknown exception";
// 	}
// }


// Path: app/src/main/java/com/arellomobile/github/mvp/common/RxUtils.java
import java.io.IOException;
import com.arellomobile.github.app.GithubError;
import retrofit2.Call;
import retrofit2.Response;
import rx.Observable;
import rx.Scheduler;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

package com.arellomobile.github.mvp.common;




/**
 * Date: 18.01.2016
 * Time: 14:37
 *
 * @author Yuri Shmakov
 */
public class RxUtils {
	public static <T> Observable<T> wrapRetrofitCall(final Call<T> call) {
		return Observable.create(subscriber ->
		{
			final Response<T> execute;
			try {
				execute = call.execute();
			} catch (IOException e) {
				subscriber.onError(e);
				return;
			}

			if (execute.isSuccess()) {
				subscriber.onNext(execute.body());
			} else {
				subscriber.onError(new GithubError(execute.errorBody()));