File tree Expand file tree Collapse file tree 4 files changed +39
-4
lines changed
app/src/main/java/com/aries/library/fast/demo
library/src/main/java/com/aries/library/fast/retrofit Expand file tree Collapse file tree 4 files changed +39
-4
lines changed Original file line number Diff line number Diff line change 1
1
package com .aries .library .fast .demo .base ;
2
2
3
3
/**
4
- * Created: AriesHoo on 2017/6/29 16:39
5
- * Function:
6
- * Desc:
4
+ * @Author: AriesHoo on 2019/7/11 22:00
5
+ * @E-Mail: AriesHoo@126.com
6
+ * @Function:
7
+ * @Description:
7
8
*/
8
9
public class BaseEntity <T > {
10
+
11
+ public boolean success ;
9
12
public int code ;
10
13
public String msg ;
11
14
public T data ;
Original file line number Diff line number Diff line change 3
3
import android .accounts .NetworkErrorException ;
4
4
5
5
import com .aries .library .fast .demo .base .BaseEntity ;
6
+ import com .aries .library .fast .retrofit .FastNullException ;
6
7
import com .aries .library .fast .retrofit .FastRetryWhen ;
7
8
import com .aries .library .fast .retrofit .FastTransformer ;
8
9
@@ -30,7 +31,12 @@ protected <T> Observable<T> transform(Observable<BaseEntity<T>> observable) {
30
31
if (result == null ) {
31
32
return Observable .error (new NetworkErrorException ());
32
33
} else {
33
- return Observable .just (result .data );
34
+ if (result .success ) {
35
+ return result .data != null ? Observable .just (result .data )
36
+ : Observable .error (new FastNullException ());
37
+ } else {
38
+ return Observable .error (new NetworkErrorException ());
39
+ }
34
40
}
35
41
}));
36
42
}
Original file line number Diff line number Diff line change
1
+ package com .aries .library .fast .retrofit ;
2
+
3
+ /**
4
+ * @Author: AriesHoo on 2019/7/11 21:55
5
+ * @E-Mail: AriesHoo@126.com
6
+ * @Function: 特定空对象Exception 用于解决接口某些情况下数据null无法回调{@link FastObserver#_onNext(Object)}的情况
7
+ * @Description:
8
+ */
9
+ public class FastNullException extends Exception {
10
+
11
+ public FastNullException (String message ) {
12
+ super (message );
13
+ }
14
+
15
+ public FastNullException (String message , Throwable cause ) {
16
+ super (message , cause );
17
+ }
18
+
19
+ public FastNullException (Throwable cause ) {
20
+ super (cause );
21
+ }
22
+ }
Original file line number Diff line number Diff line change @@ -34,6 +34,10 @@ public void onComplete() {
34
34
35
35
@ Override
36
36
public void onError (Throwable e ) {
37
+ if (e instanceof FastNullException ) {
38
+ _onNext (null );
39
+ return ;
40
+ }
37
41
if (FastManager .getInstance ().getHttpRequestControl () != null ) {
38
42
FastManager .getInstance ().getHttpRequestControl ().httpRequestError (mHttpRequestControl , e );
39
43
}
You can’t perform that action at this time.
0 commit comments