@@ -84,26 +84,23 @@ public final class Storage {
8484 }
8585
8686 func store( contentResult: Result < ContentsResponse , APIError > , completion: @escaping ( Error ? ) -> Void ) {
87- if case let . failure( error) = contentResult {
88- os_log ( " Error downloading contents: %{public}@ " ,
87+ let contentsResponse : ContentsResponse
88+ do {
89+ contentsResponse = try contentResult. get ( )
90+ } catch {
91+ os_log ( " Error downloading contents: \n %{public}@ " ,
8992 log: log,
9093 type: . error,
9194 String ( describing: error) )
92-
9395 completion ( error)
94-
95- return
96- }
97-
98- guard case let . success( sessionsResponse) = contentResult else {
9996 return
10097 }
10198
10299 performSerializedBackgroundWrite ( writeBlock: { backgroundRealm in
103- sessionsResponse . sessions. forEach { newSession in
100+ contentsResponse . sessions. forEach { newSession in
104101 // Replace any "unknown" resources with their full data
105102 newSession. related. filter ( { $0. type == RelatedResourceType . unknown. rawValue} ) . forEach { unknownResource in
106- if let fullResource = sessionsResponse . resources. filter ( { $0. identifier == unknownResource. identifier} ) . first {
103+ if let fullResource = contentsResponse . resources. filter ( { $0. identifier == unknownResource. identifier} ) . first {
107104 newSession. related. replace ( index: newSession. related. index ( of: unknownResource) !, object: fullResource)
108105 }
109106 }
@@ -117,7 +114,7 @@ public final class Storage {
117114 }
118115
119116 // Merge existing instance data, preserving user-defined data
120- sessionsResponse . instances. forEach { newInstance in
117+ contentsResponse . instances. forEach { newInstance in
121118 if let existingInstance = backgroundRealm. object ( ofType: SessionInstance . self, forPrimaryKey: newInstance. identifier) {
122119 existingInstance. merge ( with: newInstance, in: backgroundRealm)
123120 } else {
@@ -134,9 +131,9 @@ public final class Storage {
134131 }
135132
136133 // Save everything
137- backgroundRealm. add ( sessionsResponse . rooms, update: true )
138- backgroundRealm. add ( sessionsResponse . tracks, update: true )
139- backgroundRealm. add ( sessionsResponse . events, update: true )
134+ backgroundRealm. add ( contentsResponse . rooms, update: true )
135+ backgroundRealm. add ( contentsResponse . tracks, update: true )
136+ backgroundRealm. add ( contentsResponse . events, update: true )
140137
141138 // add instances to rooms
142139 backgroundRealm. objects ( Room . self) . forEach { room in
@@ -225,7 +222,16 @@ public final class Storage {
225222 }
226223
227224 internal func store( liveVideosResult: Result < [ SessionAsset ] , APIError > ) {
228- guard case . success( let assets) = liveVideosResult else { return }
225+ let assets : [ SessionAsset ]
226+ do {
227+ assets = try liveVideosResult. get ( )
228+ } catch {
229+ os_log ( " Error downloading live videos: \n %{public}@ " ,
230+ log: log,
231+ type: . error,
232+ String ( describing: error) )
233+ return
234+ }
229235
230236 performSerializedBackgroundWrite ( writeBlock: { [ weak self] backgroundRealm in
231237 guard let self = self else { return }
@@ -251,19 +257,18 @@ public final class Storage {
251257 }
252258
253259 internal func store( featuredSectionsResult: Result < [ FeaturedSection ] , APIError > , completion: @escaping ( Error ? ) -> Void ) {
254- if case let . failure( error) = featuredSectionsResult {
255- os_log ( " Error downloading featured sections: %{public}@ " ,
260+ let sections : [ FeaturedSection ]
261+ do {
262+ sections = try featuredSectionsResult. get ( )
263+ } catch {
264+ os_log ( " Error downloading featured sections: \n %{public}@ " ,
256265 log: log,
257266 type: . error,
258267 String ( describing: error) )
259-
260268 completion ( error)
261-
262269 return
263270 }
264271
265- guard case . success( let sections) = featuredSectionsResult else { return }
266-
267272 performSerializedBackgroundWrite ( writeBlock: { backgroundRealm in
268273 let existingSections = backgroundRealm. objects ( FeaturedSection . self)
269274 for section in existingSections {
0 commit comments