Skip to content

Commit 021b8cb

Browse files
committed
Only cache assets if server responses with 2xx or 3xx status code
1 parent cfe2950 commit 021b8cb

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

ios/Sources/GutenbergKit/Sources/EditorAssetsLibrary.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,12 @@ public actor EditorAssetsLibrary {
9999
try fileManager.createDirectory(at: localURL.deletingLastPathComponent(), withIntermediateDirectories: true)
100100
}
101101

102-
let (downloaded, _) = try await urlSession.download(from: httpURL)
103-
try fileManager.moveItem(at: downloaded, to: localURL)
102+
let (downloaded, response) = try await urlSession.download(from: httpURL)
103+
if let status = (response as? HTTPURLResponse)?.statusCode, (200..<300).contains(status) {
104+
try fileManager.moveItem(at: downloaded, to: localURL)
105+
} else {
106+
throw URLError(.badServerResponse)
107+
}
104108
}
105109

106110
return localURL

0 commit comments

Comments
 (0)