Skip to content

Commit

Permalink
feat: add AnalyticsError type for setting fetch failed.
Browse files Browse the repository at this point in the history
  • Loading branch information
didiergarcia committed Oct 4, 2024
1 parent 41df310 commit 8ae5580
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Sources/Segment/Errors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public enum AnalyticsError: Error {
case pluginError(Error)

case enrichmentError(String)

case settingsFetchError(Error)
}

extension Analytics {
Expand Down
8 changes: 4 additions & 4 deletions Sources/Segment/Utilities/Networking/HTTPClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,21 +128,21 @@ public class HTTPClient {

let dataTask = session.dataTask(with: urlRequest) { [weak self] (data, response, error) in
if let error = error {
self?.analytics?.reportInternalError(AnalyticsError.networkUnknown(error))
self?.analytics?.reportInternalError(AnalyticsError.settingsFetchError(AnalyticsError.networkUnknown(error)))
completion(false, nil)
return
}

if let httpResponse = response as? HTTPURLResponse {
if httpResponse.statusCode > 300 {
self?.analytics?.reportInternalError(AnalyticsError.networkUnexpectedHTTPCode(httpResponse.statusCode))
self?.analytics?.reportInternalError(AnalyticsError.settingsFetchError(AnalyticsError.networkUnexpectedHTTPCode(httpResponse.statusCode)))
completion(false, nil)
return
}
}

guard let data = data else {
self?.analytics?.reportInternalError(AnalyticsError.networkInvalidData)
self?.analytics?.reportInternalError(AnalyticsError.settingsFetchError(AnalyticsError.networkInvalidData))
completion(false, nil)
return
}
Expand All @@ -151,7 +151,7 @@ public class HTTPClient {
let responseJSON = try JSONDecoder.default.decode(Settings.self, from: data)
completion(true, responseJSON)
} catch {
self?.analytics?.reportInternalError(AnalyticsError.jsonUnableToDeserialize(error))
self?.analytics?.reportInternalError(AnalyticsError.settingsFetchError(AnalyticsError.jsonUnableToDeserialize(error)))
completion(false, nil)
return
}
Expand Down

0 comments on commit 8ae5580

Please sign in to comment.