@@ -5,7 +5,7 @@ import SotoElasticsearchService
5
5
extension ElasticsearchClient {
6
6
public func bulk< Document: Encodable > ( _ operations: [ ESBulkOperation < Document > ] ) -> EventLoopFuture < ESBulkResponse > {
7
7
guard operations. count > 0 else {
8
- return self . eventLoop. makeFailedFuture ( ElasticSearchClientError ( message: " No operations to perform for the bulk API " ) )
8
+ return self . eventLoop. makeFailedFuture ( ElasticSearchClientError ( message: " No operations to perform for the bulk API " , status : nil ) )
9
9
}
10
10
do {
11
11
let url = try buildURL ( path: " /_bulk " )
@@ -15,42 +15,42 @@ extension ElasticsearchClient {
15
15
switch operation. operationType {
16
16
case . create:
17
17
guard let document = operation. document else {
18
- return self . eventLoop. makeFailedFuture ( ElasticSearchClientError ( message: " No document provided for create bulk operation " ) )
18
+ return self . eventLoop. makeFailedFuture ( ElasticSearchClientError ( message: " No document provided for create bulk operation " , status : nil ) )
19
19
}
20
20
let createInfo = BulkCreate ( create: bulkOperationBody)
21
21
let createLine = try self . jsonEncoder. encode ( createInfo)
22
22
let dataLine = try self . jsonEncoder. encode ( document)
23
23
guard let createLineString = String ( data: createLine, encoding: . utf8) , let dataLineString = String ( data: dataLine, encoding: . utf8) else {
24
- throw ElasticSearchClientError ( message: " Failed to convert bulk data from Data to String " )
24
+ throw ElasticSearchClientError ( message: " Failed to convert bulk data from Data to String " , status : nil )
25
25
}
26
26
bodyString. append ( " \( createLineString) \n \( dataLineString) \n " )
27
27
case . delete:
28
28
let deleteInfo = BulkDelete ( delete: bulkOperationBody)
29
29
let deleteLine = try self . jsonEncoder. encode ( deleteInfo)
30
30
guard let deleteLineString = String ( data: deleteLine, encoding: . utf8) else {
31
- throw ElasticSearchClientError ( message: " Failed to convert bulk data from Data to String " )
31
+ throw ElasticSearchClientError ( message: " Failed to convert bulk data from Data to String " , status : nil )
32
32
}
33
33
bodyString. append ( " \( deleteLineString) \n " )
34
34
case . index:
35
35
guard let document = operation. document else {
36
- return self . eventLoop. makeFailedFuture ( ElasticSearchClientError ( message: " No document provided for create bulk operation " ) )
36
+ return self . eventLoop. makeFailedFuture ( ElasticSearchClientError ( message: " No document provided for create bulk operation " , status : nil ) )
37
37
}
38
38
let indexInfo = BulkIndex ( index: bulkOperationBody)
39
39
let indexLine = try self . jsonEncoder. encode ( indexInfo)
40
40
let dataLine = try self . jsonEncoder. encode ( document)
41
41
guard let indexLineString = String ( data: indexLine, encoding: . utf8) , let dataLineString = String ( data: dataLine, encoding: . utf8) else {
42
- throw ElasticSearchClientError ( message: " Failed to convert bulk data from Data to String " )
42
+ throw ElasticSearchClientError ( message: " Failed to convert bulk data from Data to String " , status : nil )
43
43
}
44
44
bodyString. append ( " \( indexLineString) \n \( dataLineString) \n " )
45
45
case . update:
46
46
guard let document = operation. document else {
47
- return self . eventLoop. makeFailedFuture ( ElasticSearchClientError ( message: " No document provided for create bulk operation " ) )
47
+ return self . eventLoop. makeFailedFuture ( ElasticSearchClientError ( message: " No document provided for create bulk operation " , status : nil ) )
48
48
}
49
49
let updateInfo = BulkUpdate ( update: bulkOperationBody)
50
50
let updateLine = try self . jsonEncoder. encode ( updateInfo)
51
51
let dataLine = try self . jsonEncoder. encode ( BulkUpdateDocument ( doc: document) )
52
52
guard let updateLineString = String ( data: updateLine, encoding: . utf8) , let dataLineString = String ( data: dataLine, encoding: . utf8) else {
53
- throw ElasticSearchClientError ( message: " Failed to convert bulk data from Data to String " )
53
+ throw ElasticSearchClientError ( message: " Failed to convert bulk data from Data to String " , status : nil )
54
54
}
55
55
bodyString. append ( " \( updateLineString) \n \( dataLineString) \n " )
56
56
}
@@ -158,7 +158,7 @@ extension ElasticsearchClient {
158
158
let url = try buildURL ( path: " / \( name) " )
159
159
return signAndExecuteRequest ( url: url, method: . HEAD, headers: . init( ) , body: . empty) . flatMapThrowing { response in
160
160
guard response. status == . ok || response. status == . notFound else {
161
- throw ElasticSearchClientError ( message: " Invalid response from index exists API - \( response) " )
161
+ throw ElasticSearchClientError ( message: " Invalid response from index exists API - \( response) " , status : response . status . code )
162
162
}
163
163
return response. status == . ok
164
164
}
0 commit comments