|
113 | 113 |
|
114 | 114 | static get(ids, fetchReference = true) {
|
115 | 115 | return new Promise((resolve, reject) => {
|
116 |
| - var x; |
| 116 | + var previousError, x; |
117 | 117 | /*
|
118 | 118 | Fetch the document with id or ids.
|
119 | 119 | If the document is not exist, it will return null.
|
|
144 | 144 | }
|
145 | 145 | // fetch documents
|
146 | 146 | if (ids.constructor === Array) {
|
| 147 | + previousError = new Error('From previous stack'); |
147 | 148 | this._es.mget({
|
148 | 149 | index: this.getIndexName(),
|
149 | 150 | type: this.getDocumentType(),
|
|
153 | 154 | }, (error, response) => {
|
154 | 155 | var dbField, doc, i, item, len, property, propertyName, ref, ref1, ref2, result;
|
155 | 156 | if (error) {
|
| 157 | + error.stack += previousError.stack; |
156 | 158 | return reject(error);
|
157 | 159 | }
|
158 | 160 | result = [];
|
|
190 | 192 | return;
|
191 | 193 | }
|
192 | 194 | // fetch the document
|
| 195 | + previousError = new Error('From previous stack'); |
193 | 196 | return this._es.get({
|
194 | 197 | index: this.getIndexName(),
|
195 | 198 | type: this.getDocumentType(),
|
196 | 199 | id: ids
|
197 | 200 | }, (error, response) => {
|
198 | 201 | var args, dbField, document, property, propertyName, ref, ref1;
|
199 | 202 | if (error) {
|
| 203 | + error.stack += previousError.stack; |
200 | 204 | if (error.status === 404) {
|
201 | 205 | return resolve(null);
|
202 | 206 | }
|
|
236 | 240 | @param id {string} The documents' id.
|
237 | 241 | @returns {promise<bool>}
|
238 | 242 | */
|
| 243 | + var previousError; |
| 244 | + previousError = new Error('From previous stack'); |
239 | 245 | return this._es.exists({
|
240 | 246 | index: this.getIndexName(),
|
241 | 247 | type: this.getDocumentType(),
|
242 | 248 | id: id
|
243 | 249 | }, function(error, response) {
|
244 | 250 | if (error) {
|
| 251 | + error.stack += previousError.stack; |
245 | 252 | return reject(error);
|
246 | 253 | }
|
247 | 254 | return resolve(response);
|
|
269 | 276 |
|
270 | 277 | static refresh(args = {}) {
|
271 | 278 | return new Promise((resolve, reject) => {
|
| 279 | + var previousError; |
272 | 280 | /*
|
273 | 281 | Explicitly refresh one or more index, making all operations performed since the last refresh available for search.
|
274 | 282 | https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference-5-6.html#api-indices-refresh-5-6
|
275 | 283 | @params args {object}
|
276 | 284 | @returns {promise}
|
277 | 285 | */
|
278 | 286 | args.index = this.getIndexName();
|
| 287 | + previousError = new Error('From previous stack'); |
279 | 288 | return this._es.indices.refresh(args, function(error) {
|
280 | 289 | if (error) {
|
| 290 | + error.stack += previousError.stack; |
281 | 291 | return reject(error);
|
282 | 292 | }
|
283 | 293 | return resolve();
|
|
295 | 305 | var closeIndex, createIndex, openIndex, putMapping, putSettings;
|
296 | 306 | createIndex = () => {
|
297 | 307 | return new Promise((resolve, reject) => {
|
| 308 | + var previousError; |
| 309 | + previousError = new Error('From previous stack'); |
298 | 310 | return this._es.indices.create({
|
299 | 311 | index: this.getIndexName()
|
300 | 312 | }, function(error, response) {
|
301 | 313 | if (error && error.status !== 400) {
|
| 314 | + error.stack += previousError.stack; |
302 | 315 | return reject(error);
|
303 | 316 | }
|
304 | 317 | return setTimeout(function() {
|
|
309 | 322 | };
|
310 | 323 | closeIndex = () => {
|
311 | 324 | return new Promise((resolve, reject) => {
|
| 325 | + var previousError; |
| 326 | + previousError = new Error('From previous stack'); |
312 | 327 | return this._es.indices.close({
|
313 | 328 | index: this.getIndexName()
|
314 | 329 | }, function(error, response) {
|
315 | 330 | if (error) {
|
| 331 | + error.stack += previousError.stack; |
316 | 332 | return reject(error);
|
317 | 333 | }
|
318 | 334 | return resolve(response);
|
|
321 | 337 | };
|
322 | 338 | putSettings = () => {
|
323 | 339 | return new Promise((resolve, reject) => {
|
| 340 | + var previousError; |
324 | 341 | if (!this._settings) {
|
325 | 342 | return resolve();
|
326 | 343 | }
|
| 344 | + previousError = new Error('From previous stack'); |
327 | 345 | return this._es.indices.putSettings({
|
328 | 346 | index: this.getIndexName(),
|
329 | 347 | body: {
|
|
333 | 351 | }
|
334 | 352 | }, function(error, response) {
|
335 | 353 | if (error) {
|
| 354 | + error.stack += previousError.stack; |
336 | 355 | return reject(error);
|
337 | 356 | }
|
338 | 357 | return resolve(response);
|
|
341 | 360 | };
|
342 | 361 | putMapping = () => {
|
343 | 362 | return new Promise((resolve, reject) => {
|
344 |
| - var field, mapping, property, propertyName, ref, ref1, ref2, ref3; |
| 363 | + var field, mapping, previousError, property, propertyName, ref, ref1, ref2, ref3; |
345 | 364 | mapping = {};
|
346 | 365 | ref = this._properties;
|
347 | 366 | for (propertyName in ref) {
|
|
428 | 447 | mapping[(ref3 = property.dbField) != null ? ref3 : propertyName] = field;
|
429 | 448 | }
|
430 | 449 | }
|
| 450 | + previousError = new Error('From previous stack'); |
431 | 451 | return this._es.indices.putMapping({
|
432 | 452 | index: this.getIndexName(),
|
433 | 453 | type: this.getDocumentType(),
|
|
436 | 456 | }
|
437 | 457 | }, function(error, response) {
|
438 | 458 | if (error) {
|
| 459 | + error.stack += previousError.stack; |
439 | 460 | return reject(error);
|
440 | 461 | }
|
441 | 462 | return resolve(response);
|
|
444 | 465 | };
|
445 | 466 | openIndex = () => {
|
446 | 467 | return new Promise((resolve, reject) => {
|
| 468 | + var previousError; |
| 469 | + previousError = new Error('From previous stack'); |
447 | 470 | return this._es.indices.open({
|
448 | 471 | index: this.getIndexName()
|
449 | 472 | }, function(error, response) {
|
450 | 473 | if (error) {
|
| 474 | + error.stack += previousError.stack; |
451 | 475 | return reject(error);
|
452 | 476 | }
|
453 | 477 | return resolve(response);
|
|
464 | 488 |
|
465 | 489 | save(refresh = false) {
|
466 | 490 | return new Promise((resolve, reject) => {
|
467 |
| - var args, convertError, dbFieldName, document, error, property, propertyName, ref, ref1, ref2; |
| 491 | + var args, convertError, dbFieldName, document, error, previousError, property, propertyName, ref, ref1, ref2; |
468 | 492 | /*
|
469 | 493 | Save this document.
|
470 | 494 | @param refresh {bool} Refresh the index after performing the operation.
|
|
509 | 533 | body: document
|
510 | 534 | };
|
511 | 535 | }
|
| 536 | + previousError = new Error('From previous stack'); |
512 | 537 | return this.constructor._es.index(args, (error, response) => {
|
513 | 538 | if (error) {
|
| 539 | + error.stack += previousError.stack; |
514 | 540 | return reject(error);
|
515 | 541 | }
|
516 | 542 | this.id = response._id;
|
|
526 | 552 | Delete this document.
|
527 | 553 | @returns {promise<Document>}
|
528 | 554 | */
|
| 555 | + var previousError; |
| 556 | + previousError = new Error('From previous stack'); |
529 | 557 | return this.constructor._es.delete({
|
530 | 558 | index: this.constructor.getIndexName(),
|
531 | 559 | type: this.constructor.getDocumentType(),
|
532 | 560 | refresh: refresh,
|
533 | 561 | id: this.id
|
534 | 562 | }, (error) => {
|
535 | 563 | if (error) {
|
| 564 | + error.stack += previousError.stack; |
536 | 565 | return reject(error);
|
537 | 566 | }
|
538 | 567 | return resolve(this);
|
|
0 commit comments