Skip to content

Commit 8ae5580

Browse files
committed
feat: add AnalyticsError type for setting fetch failed.
1 parent 41df310 commit 8ae5580

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

Sources/Segment/Errors.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public enum AnalyticsError: Error {
2929
case pluginError(Error)
3030

3131
case enrichmentError(String)
32+
33+
case settingsFetchError(Error)
3234
}
3335

3436
extension Analytics {

Sources/Segment/Utilities/Networking/HTTPClient.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,21 +128,21 @@ public class HTTPClient {
128128

129129
let dataTask = session.dataTask(with: urlRequest) { [weak self] (data, response, error) in
130130
if let error = error {
131-
self?.analytics?.reportInternalError(AnalyticsError.networkUnknown(error))
131+
self?.analytics?.reportInternalError(AnalyticsError.settingsFetchError(AnalyticsError.networkUnknown(error)))
132132
completion(false, nil)
133133
return
134134
}
135135

136136
if let httpResponse = response as? HTTPURLResponse {
137137
if httpResponse.statusCode > 300 {
138-
self?.analytics?.reportInternalError(AnalyticsError.networkUnexpectedHTTPCode(httpResponse.statusCode))
138+
self?.analytics?.reportInternalError(AnalyticsError.settingsFetchError(AnalyticsError.networkUnexpectedHTTPCode(httpResponse.statusCode)))
139139
completion(false, nil)
140140
return
141141
}
142142
}
143143

144144
guard let data = data else {
145-
self?.analytics?.reportInternalError(AnalyticsError.networkInvalidData)
145+
self?.analytics?.reportInternalError(AnalyticsError.settingsFetchError(AnalyticsError.networkInvalidData))
146146
completion(false, nil)
147147
return
148148
}
@@ -151,7 +151,7 @@ public class HTTPClient {
151151
let responseJSON = try JSONDecoder.default.decode(Settings.self, from: data)
152152
completion(true, responseJSON)
153153
} catch {
154-
self?.analytics?.reportInternalError(AnalyticsError.jsonUnableToDeserialize(error))
154+
self?.analytics?.reportInternalError(AnalyticsError.settingsFetchError(AnalyticsError.jsonUnableToDeserialize(error)))
155155
completion(false, nil)
156156
return
157157
}

0 commit comments

Comments
 (0)