-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from niklhut/elasticsearch-8.4
Elasticsearch 8.4 and URL initializer
- Loading branch information
Showing
6 changed files
with
157 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
Sources/ElasticsearchNIOClient/ElasticsearchClient+ValidationError.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import Foundation | ||
|
||
extension ElasticsearchClient { | ||
public struct ValidationError: LocalizedError, Equatable { | ||
public static let invalidURLString = ValidationError(.invalidURLString) | ||
public static let missingURLScheme = ValidationError(.missingURLScheme) | ||
public static let invalidURLScheme = ValidationError(.invalidURLScheme) | ||
public static let missingURLHost = ValidationError(.missingURLHost) | ||
|
||
var localizedDescription: String { self.kind.localizedDescription } | ||
|
||
private let kind: Kind | ||
|
||
private init(_ kind: Kind) { self.kind = kind } | ||
|
||
public static func ==(lhs: ValidationError, rhs: ValidationError) -> Bool { | ||
return lhs.kind == rhs.kind | ||
} | ||
|
||
private enum Kind: LocalizedError { | ||
case invalidURLString | ||
case missingURLScheme | ||
case invalidURLScheme | ||
case missingURLHost | ||
|
||
var localizedDescription: String { | ||
let message: String = { | ||
switch self { | ||
case .invalidURLString: return "invalid URL string" | ||
case .missingURLScheme: return "URL scheme is missing" | ||
case .invalidURLScheme: return "invalid URL scheme, expected 'http' or 'https'" | ||
case .missingURLHost: return "missing remote hostname" | ||
} | ||
}() | ||
return "Elasticsearch connection configuration validation failed: \(message)" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters