Skip to content

Commit 450d29b

Browse files
authored
Provide descriptive error when the stylesheet cannot be found (#1499)
* Throw error when the stylesheet cannot be downloaded * Use range for status code check
1 parent c2eef53 commit 450d29b

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Sources/LiveViewNative/Coordinators/LiveSessionCoordinator.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,11 @@ public class LiveSessionCoordinator<R: RootRegistry>: ObservableObject {
238238
if let cachedStylesheet = await StylesheetCache.shared.read(for: url, registry: R.self) {
239239
return cachedStylesheet
240240
} else {
241-
let (data, _) = try await self.urlSession.data(from: url)
241+
let (data, response) = try await self.urlSession.data(from: url)
242+
if let response = response as? HTTPURLResponse,
243+
!(200...299).contains(response.statusCode) {
244+
throw AnyLocalizedError(errorDescription: "Downloading stylesheet '\(url.absoluteString)' failed with status code \(response.statusCode)")
245+
}
242246
guard let contents = String(data: data, encoding: .utf8)
243247
else { return await Stylesheet<R>(content: [], classes: [:]) }
244248
let stylesheet = try await Stylesheet<R>(from: contents, in: .init())

0 commit comments

Comments
 (0)