1 | mixin = require './mixin'
|
2 |
|
3 | module.exports = (client, _opts) -> (bulk, callback) ->
|
4 | opts = mixin _opts, body:bulk
|
5 | client.bulk(opts).then (res) ->
|
6 | if res?.errors
|
7 | # { index: { _index: 'blah', _type: 'ttninjs', _id: 'sdltb459b78', status: 400,
|
8 | # error: { type: 'mapper_parsing_exception',
|
9 | # reason: 'Field name [sdl.archivedBy] cannot contain \'.\''
|
10 | # } } }
|
11 | oper = OPERS.find (oper) -> res.items[0]?[oper]
|
12 | reason = res.items[0]?[oper]?.error?.reason
|
13 | if reason
|
14 | callback new Error(reason)
|
15 | else
|
16 | callback res
|
17 | else
|
18 | callback null, res
|
19 | .catch (err) ->
|
20 | callback err
|