Skip to content

Commit

Permalink
refactor: Remove unused errors
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziodemaria committed Jun 26, 2024
1 parent 2ffc41d commit 4e5ae0a
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 45 deletions.
11 changes: 2 additions & 9 deletions Sources/Confidence/Apply/FlagApplierWithRetries.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,8 @@ final class FlagApplierWithRetries: FlagApplier {
}

private func logApplyError(error: Error) {
switch error {
case ConfidenceError.applyStatusTransitionError, ConfidenceError.cachedValueExpired,
ConfidenceError.flagNotFoundInCache:
Logger(subsystem: "com.confidence.provider", category: "apply").debug(
"Cache data for flag was updated while executing \"apply\", aborting")
default:
Logger(subsystem: "com.confidence.provider", category: "apply").error(
"Error while executing \"apply\": \(error)")
}
Logger(subsystem: "com.confidence.provider", category: "apply").error(
"Error while executing \"apply\": \(error)")
}
}

Expand Down
36 changes: 2 additions & 34 deletions Sources/Confidence/ConfidenceError.swift
Original file line number Diff line number Diff line change
@@ -1,55 +1,27 @@
import Foundation

public enum ConfidenceError: Error, Equatable {
/// Signifies that the provider is not connected to the Confidence backend
case providerNotConnected
/// GRPC-specific error during the connection
case grpcError(message: String)
/// Error while caching a resolve or retrieving a cached resolve
case cacheError(message: String)
/// Corrupted cache file
case corruptedCache(message: String)
/// Flag not found in cache
case flagNotFoundInCache
case flagNotFoundError(key: String)
/// Value in cache expired
case cachedValueExpired
/// Apply state transition not allowed
case applyStatusTransitionError
/// No resolveToken returned by the server
case noResolveTokenFromServer
/// No resolveToken in the cache
case noResolveTokenFromCache
/// Bad request from provider
case badRequest(message: String?)
/// Internal error
case internalError(message: String)
case parseError(message: String)
case invalidContextError
case invalidContextInMessage
}

extension ConfidenceError: CustomStringConvertible {
public var description: String {
switch self {
case .providerNotConnected:
return "The provider is not connected"
case .grpcError(let message):
return message
case .cacheError(let message):
return message
case .corruptedCache(let message):
return message
case .flagNotFoundInCache:
return "Flag not found in the cache"
case .cachedValueExpired:
return "Cached flag has an old evaluation context"
case .applyStatusTransitionError:
return "Apply status transition error"
case .noResolveTokenFromServer:
return "No resolver token returned by the server"
case .noResolveTokenFromCache:
return "No resolver token in cache, cache needs refresh"
case .flagNotFoundError(let key):
return "Flag not found for key \(key)"
case .badRequest(let message):
guard let message = message else {
return "Bad request from provider"
Expand All @@ -59,10 +31,6 @@ extension ConfidenceError: CustomStringConvertible {
return "An internal error occurred: \(message)"
case .parseError(let message):
return "Parse error occurred: \(message)"
case .flagNotFoundError(let key):
return "Flag not found for key \(key)"
case .invalidContextError:
return "Invalid context error"
case .invalidContextInMessage:
return "Field 'context' is not allowed in event's data"
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Confidence/Http/HttpClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ extension HTTPURLResponse {

switch self.status {
case .notFound, .badRequest:
return ConfidenceError.badRequest(message: error?.message ?? "")
return ConfidenceError.badRequest(message: error?.message)
default:
return defaultError
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Confidence/HttpStatusCode+Error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extension HTTPURLResponse {
case .notFound:
return ConfidenceError.flagNotFoundError(key: flag)
case .badRequest:
return ConfidenceError.badRequest(message: error?.message ?? "")
return ConfidenceError.badRequest(message: error?.message)
default:
return defaultError
}
Expand Down

0 comments on commit 4e5ae0a

Please sign in to comment.