-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProfileImageDataServiceImpl.swift
More file actions
52 lines (47 loc) · 1.49 KB
/
Copy pathProfileImageDataServiceImpl.swift
File metadata and controls
52 lines (47 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//
// ProfileImageDataServiceImpl.swift
// DevLogInfra
//
// Created by opfic on 6/11/26.
//
import Foundation
import Nexa
import DevLogData
final class ProfileImageDataServiceImpl: ProfileImageDataService {
private enum CrashlyticsError {
static let domain = "DevLogInfra.ProfileImageDataServiceImpl"
enum Code: Int {
case fetchImageData = 1
}
}
func fetchImageData(from url: URL) async throws -> Data {
do {
return try await NXAPIClient(
configuration: NXClientConfiguration(baseURL: url)
)
.get()
.timeout(10)
.intercept(ProfileImageDataCachePolicyInterceptor())
.validate(.successStatusCode)
.raw()
.data
} catch {
FirebaseCrashlyticsHelper.record(
error,
domain: "\(CrashlyticsError.domain).\(CrashlyticsError.Code.fetchImageData)",
code: CrashlyticsError.Code.fetchImageData.rawValue
)
throw error
}
}
}
private struct ProfileImageDataCachePolicyInterceptor: NXHTTPInterceptor {
func intercept(
context: NXRequestExecutionContext,
next: @escaping @Sendable (NXRequestExecutionContext) async throws -> NXRawResponse
) async throws -> NXRawResponse {
var request = context.request
request.cachePolicy = .reloadIgnoringLocalCacheData
return try await next(context.replacingRequest(request))
}
}