com.cmonbaby.http.core.HttpCallback Maven / Gradle / Ivy
package com.cmonbaby.http.core;
import android.util.Log;
import com.cmonbaby.http.exception.ExceptionHandle;
import rx.Observer;
/**
* Author: Simon
*
QO: 8950764
*
Email: [email protected]
*
WebSize: https://www.cmonbaby.com
*
Version: 1.0.0
*
Date: 2020/12/28
*
Description: 请求回调接口
*/
public abstract class HttpCallback implements Observer {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
if(e instanceof ExceptionHandle.ResponeThrowable){
onFailed(ExceptionHandle.handleException(e));
} else {
onError(new ExceptionHandle.ResponeThrowable(e, ExceptionHandle.ERROR.UNKNOWN));
}
}
@Override
public void onNext(T t) {
onSuccessful(t);
}
private void onFailed(ExceptionHandle.ResponeThrowable e) {
Log.e(" onError() >>> ", e == null ? "无法连接服务器" : e.message);
}
public abstract void onSuccessful(T t);
}