in Sources/Hub/HubApi.swift [90:117]
func httpGet(for url: URL) async throws -> (Data, HTTPURLResponse) {
var request = URLRequest(url: url)
if let hfToken {
request.setValue("Bearer \(hfToken)", forHTTPHeaderField: "Authorization")
}
do {
let (data, response) = try await URLSession.shared.data(for: request)
guard let httpResponse = response as? HTTPURLResponse else {
throw Hub.HubClientError.unexpectedError
}
switch httpResponse.statusCode {
case 200..<300:
return (data, httpResponse)
case 401, 403:
throw Hub.HubClientError.authorizationRequired
case 404:
throw Hub.HubClientError.fileNotFound(url.lastPathComponent)
default:
throw Hub.HubClientError.httpStatusCode(httpResponse.statusCode)
}
} catch let error as Hub.HubClientError {
throw error
} catch {
throw Hub.HubClientError.downloadError(error.localizedDescription)
}
}