55 * you may not use this file except in compliance with the License.
66 * You may obtain a copy of the License at
77 *
8- * http://www.apache.org/licenses/LICENSE-2.0
8+ * http://www.apache.org/licenses/LICENSE-2.0
99 *
1010 * Unless required by applicable law or agreed to in writing, software
1111 * distributed under the License is distributed on an "AS IS" BASIS,
2525import java .net .MalformedURLException ;
2626import java .util .List ;
2727import rx .Observable ;
28- import rx .Subscriber ;
2928
3029/**
3130 * {@link RestApi} implementation for retrieving data from the network.
@@ -51,49 +50,43 @@ public RestApiImpl(Context context, UserEntityJsonMapper userEntityJsonMapper) {
5150
5251 @ RxLogObservable
5352 @ Override public Observable <List <UserEntity >> userEntityList () {
54- return Observable .create (new Observable .OnSubscribe <List <UserEntity >>() {
55- @ Override public void call (Subscriber <? super List <UserEntity >> subscriber ) {
56-
57- if (isThereInternetConnection ()) {
58- try {
59- String responseUserEntities = getUserEntitiesFromApi ();
60- if (responseUserEntities != null ) {
61- subscriber .onNext (userEntityJsonMapper .transformUserEntityCollection (
62- responseUserEntities ));
63- subscriber .onCompleted ();
64- } else {
65- subscriber .onError (new NetworkConnectionException ());
66- }
67- } catch (Exception e ) {
68- subscriber .onError (new NetworkConnectionException (e .getCause ()));
53+ return Observable .create (subscriber -> {
54+ if (isThereInternetConnection ()) {
55+ try {
56+ String responseUserEntities = getUserEntitiesFromApi ();
57+ if (responseUserEntities != null ) {
58+ subscriber .onNext (userEntityJsonMapper .transformUserEntityCollection (
59+ responseUserEntities ));
60+ subscriber .onCompleted ();
61+ } else {
62+ subscriber .onError (new NetworkConnectionException ());
6963 }
70- } else {
71- subscriber .onError (new NetworkConnectionException ());
64+ } catch ( Exception e ) {
65+ subscriber .onError (new NetworkConnectionException (e . getCause () ));
7266 }
67+ } else {
68+ subscriber .onError (new NetworkConnectionException ());
7369 }
7470 });
7571 }
7672
7773 @ RxLogObservable
7874 @ Override public Observable <UserEntity > userEntityById (final int userId ) {
79- return Observable .create (new Observable .OnSubscribe <UserEntity >() {
80- @ Override public void call (Subscriber <? super UserEntity > subscriber ) {
81-
82- if (isThereInternetConnection ()) {
83- try {
84- String responseUserDetails = getUserDetailsFromApi (userId );
85- if (responseUserDetails != null ) {
86- subscriber .onNext (userEntityJsonMapper .transformUserEntity (responseUserDetails ));
87- subscriber .onCompleted ();
88- } else {
89- subscriber .onError (new NetworkConnectionException ());
90- }
91- } catch (Exception e ) {
92- subscriber .onError (new NetworkConnectionException (e .getCause ()));
75+ return Observable .create (subscriber -> {
76+ if (isThereInternetConnection ()) {
77+ try {
78+ String responseUserDetails = getUserDetailsFromApi (userId );
79+ if (responseUserDetails != null ) {
80+ subscriber .onNext (userEntityJsonMapper .transformUserEntity (responseUserDetails ));
81+ subscriber .onCompleted ();
82+ } else {
83+ subscriber .onError (new NetworkConnectionException ());
9384 }
94- } else {
95- subscriber .onError (new NetworkConnectionException ());
85+ } catch ( Exception e ) {
86+ subscriber .onError (new NetworkConnectionException (e . getCause () ));
9687 }
88+ } else {
89+ subscriber .onError (new NetworkConnectionException ());
9790 }
9891 });
9992 }
0 commit comments