@@ -5,7 +5,7 @@ import SotoElasticsearchService
55extension ElasticsearchClient {
66 public func bulk< Document: Encodable > ( _ operations: [ ESBulkOperation < Document > ] ) -> EventLoopFuture < ESBulkResponse > {
77 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 ) )
99 }
1010 do {
1111 let url = try buildURL ( path: " /_bulk " )
@@ -15,42 +15,42 @@ extension ElasticsearchClient {
1515 switch operation. operationType {
1616 case . create:
1717 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 ) )
1919 }
2020 let createInfo = BulkCreate ( create: bulkOperationBody)
2121 let createLine = try self . jsonEncoder. encode ( createInfo)
2222 let dataLine = try self . jsonEncoder. encode ( document)
2323 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 )
2525 }
2626 bodyString. append ( " \( createLineString) \n \( dataLineString) \n " )
2727 case . delete:
2828 let deleteInfo = BulkDelete ( delete: bulkOperationBody)
2929 let deleteLine = try self . jsonEncoder. encode ( deleteInfo)
3030 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 )
3232 }
3333 bodyString. append ( " \( deleteLineString) \n " )
3434 case . index:
3535 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 ) )
3737 }
3838 let indexInfo = BulkIndex ( index: bulkOperationBody)
3939 let indexLine = try self . jsonEncoder. encode ( indexInfo)
4040 let dataLine = try self . jsonEncoder. encode ( document)
4141 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 )
4343 }
4444 bodyString. append ( " \( indexLineString) \n \( dataLineString) \n " )
4545 case . update:
4646 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 ) )
4848 }
4949 let updateInfo = BulkUpdate ( update: bulkOperationBody)
5050 let updateLine = try self . jsonEncoder. encode ( updateInfo)
5151 let dataLine = try self . jsonEncoder. encode ( BulkUpdateDocument ( doc: document) )
5252 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 )
5454 }
5555 bodyString. append ( " \( updateLineString) \n \( dataLineString) \n " )
5656 }
@@ -158,7 +158,7 @@ extension ElasticsearchClient {
158158 let url = try buildURL ( path: " / \( name) " )
159159 return signAndExecuteRequest ( url: url, method: . HEAD, headers: . init( ) , body: . empty) . flatMapThrowing { response in
160160 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 )
162162 }
163163 return response. status == . ok
164164 }
0 commit comments