Impressia/Vernissage/Services/RemoteFileService.swift

26 lines
695 B
Swift
Raw Normal View History

2022-12-30 18:20:54 +01:00
//
// https://mczachurski.dev
// Copyright © 2022 Marcin Czachurski and the repository contributors.
// Licensed under the MIT License.
//
import Foundation
public class RemoteFileService {
public static let shared = RemoteFileService()
2023-01-05 11:55:20 +01:00
private init() { }
2022-12-30 18:20:54 +01:00
public func fetchData(url: URL) async throws -> Data? {
let urlRequest = URLRequest(url: url)
// Fetching data.
let (data, response) = try await URLSession.shared.data(for: urlRequest)
2023-01-08 17:56:07 +01:00
guard (response as? HTTPURLResponse)?.status?.responseType == .success else {
throw NetworkError.notSuccessResponse(response)
2022-12-30 18:20:54 +01:00
}
return data
}
}