Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add AnalyticsError type for setting fetch failed. #366

Merged
merged 3 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading