File tree Expand file tree Collapse file tree 2 files changed +14
-9
lines changed
app/src/main/java/guide/graphql/toc/ui Expand file tree Collapse file tree 2 files changed +14
-9
lines changed Original file line number Diff line number Diff line change @@ -24,15 +24,18 @@ class ChaptersViewModel : ViewModel() {
24
24
25
25
if (response.hasErrors()) {
26
26
emit(Resource .error(" Response has errors" ,null ))
27
+ return @liveData
27
28
}
28
- if ( response.data?.chapters != null ) {
29
+ response.data?.chapters?. let {
29
30
emit(Resource .success(response.data!! .chapters))
30
- } else {
31
- emit(Resource .error(" Data is null" ,null ))
31
+ return @liveData
32
32
}
33
+ emit(Resource .error(" Data is null" ,null ))
34
+ return @liveData
33
35
} catch (e: ApolloException ) {
34
36
Log .d(" ChaptersQuery" , " GraphQL request failed" , e)
35
37
emit(Resource .error(" GraphQL request failed" , null ))
38
+ return @liveData
36
39
}
37
40
}
38
41
}
Original file line number Diff line number Diff line change @@ -32,20 +32,22 @@ class SectionsViewModel: ViewModel() {
32
32
33
33
if (response.hasErrors()) {
34
34
emit(Resource .error(" Response has errors" ,null ))
35
+ return @liveData
35
36
}
36
- if (response.data?.chapter != null ) {
37
- val sections = response.data!! .chapter!! .sections
37
+ response.data?.chapter?.sections?.let { sections ->
38
38
if (sections.size > 1 ) {
39
39
emit(Resource .success(sections))
40
40
} else {
41
- emit(Resource .error(" Empty sections" , null ))
41
+ emit(Resource .error(" No sections" , null ))
42
42
}
43
- } else {
44
- emit(Resource .error(" Data is empty" ,null ))
43
+ return @liveData
45
44
}
45
+ emit(Resource .error(" Chapter has no sections" ,null ))
46
+ return @liveData
46
47
} catch (e: ApolloException ) {
47
- Log .d(" ChaptersQuery " , " GraphQL request failed" , e)
48
+ Log .d(" Sections Query " , " GraphQL request failed" , e)
48
49
emit(Resource .error(" GraphQL request failed" , null ))
50
+ return @liveData
49
51
}
50
52
}
51
53
}
You can’t perform that action at this time.
0 commit comments