diff --git a/lib/document.js b/lib/document.js index 7603fbe..8fa8c34 100644 --- a/lib/document.js +++ b/lib/document.js @@ -113,7 +113,7 @@ static get(ids, fetchReference = true) { return new Promise((resolve, reject) => { - var x; + var previousError, x; /* Fetch the document with id or ids. If the document is not exist, it will return null. @@ -144,6 +144,7 @@ } // fetch documents if (ids.constructor === Array) { + previousError = new Error('From previous stack'); this._es.mget({ index: this.getIndexName(), type: this.getDocumentType(), @@ -153,6 +154,7 @@ }, (error, response) => { var dbField, doc, i, item, len, property, propertyName, ref, ref1, ref2, result; if (error) { + error.stack += previousError.stack; return reject(error); } result = []; @@ -190,6 +192,7 @@ return; } // fetch the document + previousError = new Error('From previous stack'); return this._es.get({ index: this.getIndexName(), type: this.getDocumentType(), @@ -197,6 +200,7 @@ }, (error, response) => { var args, dbField, document, property, propertyName, ref, ref1; if (error) { + error.stack += previousError.stack; if (error.status === 404) { return resolve(null); } @@ -236,12 +240,15 @@ @param id {string} The documents' id. @returns {promise} */ + var previousError; + previousError = new Error('From previous stack'); return this._es.exists({ index: this.getIndexName(), type: this.getDocumentType(), id: id }, function(error, response) { if (error) { + error.stack += previousError.stack; return reject(error); } return resolve(response); @@ -269,6 +276,7 @@ static refresh(args = {}) { return new Promise((resolve, reject) => { + var previousError; /* Explicitly refresh one or more index, making all operations performed since the last refresh available for search. https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference-5-6.html#api-indices-refresh-5-6 @@ -276,8 +284,10 @@ @returns {promise} */ args.index = this.getIndexName(); + previousError = new Error('From previous stack'); return this._es.indices.refresh(args, function(error) { if (error) { + error.stack += previousError.stack; return reject(error); } return resolve(); @@ -295,10 +305,13 @@ var closeIndex, createIndex, openIndex, putMapping, putSettings; createIndex = () => { return new Promise((resolve, reject) => { + var previousError; + previousError = new Error('From previous stack'); return this._es.indices.create({ index: this.getIndexName() }, function(error, response) { if (error && error.status !== 400) { + error.stack += previousError.stack; return reject(error); } return setTimeout(function() { @@ -309,10 +322,13 @@ }; closeIndex = () => { return new Promise((resolve, reject) => { + var previousError; + previousError = new Error('From previous stack'); return this._es.indices.close({ index: this.getIndexName() }, function(error, response) { if (error) { + error.stack += previousError.stack; return reject(error); } return resolve(response); @@ -321,9 +337,11 @@ }; putSettings = () => { return new Promise((resolve, reject) => { + var previousError; if (!this._settings) { return resolve(); } + previousError = new Error('From previous stack'); return this._es.indices.putSettings({ index: this.getIndexName(), body: { @@ -333,6 +351,7 @@ } }, function(error, response) { if (error) { + error.stack += previousError.stack; return reject(error); } return resolve(response); @@ -341,7 +360,7 @@ }; putMapping = () => { return new Promise((resolve, reject) => { - var field, mapping, property, propertyName, ref, ref1, ref2, ref3; + var field, mapping, previousError, property, propertyName, ref, ref1, ref2, ref3; mapping = {}; ref = this._properties; for (propertyName in ref) { @@ -428,6 +447,7 @@ mapping[(ref3 = property.dbField) != null ? ref3 : propertyName] = field; } } + previousError = new Error('From previous stack'); return this._es.indices.putMapping({ index: this.getIndexName(), type: this.getDocumentType(), @@ -436,6 +456,7 @@ } }, function(error, response) { if (error) { + error.stack += previousError.stack; return reject(error); } return resolve(response); @@ -444,10 +465,13 @@ }; openIndex = () => { return new Promise((resolve, reject) => { + var previousError; + previousError = new Error('From previous stack'); return this._es.indices.open({ index: this.getIndexName() }, function(error, response) { if (error) { + error.stack += previousError.stack; return reject(error); } return resolve(response); @@ -464,7 +488,7 @@ save(refresh = false) { return new Promise((resolve, reject) => { - var args, convertError, dbFieldName, document, error, property, propertyName, ref, ref1, ref2; + var args, convertError, dbFieldName, document, error, previousError, property, propertyName, ref, ref1, ref2; /* Save this document. @param refresh {bool} Refresh the index after performing the operation. @@ -509,8 +533,10 @@ body: document }; } + previousError = new Error('From previous stack'); return this.constructor._es.index(args, (error, response) => { if (error) { + error.stack += previousError.stack; return reject(error); } this.id = response._id; @@ -526,6 +552,8 @@ Delete this document. @returns {promise} */ + var previousError; + previousError = new Error('From previous stack'); return this.constructor._es.delete({ index: this.constructor.getIndexName(), type: this.constructor.getDocumentType(), @@ -533,6 +561,7 @@ id: this.id }, (error) => { if (error) { + error.stack += previousError.stack; return reject(error); } return resolve(this); diff --git a/lib/query.js b/lib/query.js index f341546..ec5a110 100644 --- a/lib/query.js +++ b/lib/query.js @@ -267,7 +267,7 @@ fetch(args = {}) { return new Promise((resolve, reject) => { - var queryObject; + var previousError, queryObject; /* Fetch documents by this query. @param args {object} @@ -293,6 +293,7 @@ }); return; } + previousError = new Error('From previous stack'); return this.documentClass._es.search({ index: this.documentClass.getIndexName(), body: { @@ -305,6 +306,7 @@ }, (error, response) => { var items, total; if (error) { + error.stack += previousError.stack; return reject(error); } items = (() => { @@ -374,8 +376,9 @@ Count documents by the query. @returns {promise} */ - var queryObject; + var previousError, queryObject; queryObject = this.compileQueries(); + previousError = new Error('From previous stack'); return this.documentClass._es.count({ index: this.documentClass.getIndexName(), body: { @@ -383,6 +386,7 @@ } }, function(error, response) { if (error) { + error.stack += previousError.stack; return reject(error); } return resolve(response.count); @@ -398,7 +402,7 @@ @param field {string} The property name of the document. @returns {promise} */ - var allFields, dbField, property, propertyName, queryObject, ref, ref1, ref2, ref3; + var allFields, dbField, previousError, property, propertyName, queryObject, ref, ref1, ref2, ref3; allFields = []; ref = this.documentClass._properties; for (propertyName in ref) { @@ -416,6 +420,7 @@ if (queryObject.isContainsEmpty) { return resolve(0); } + previousError = new Error('From previous stack'); return this.documentClass._es.search({ index: this.documentClass.getIndexName(), body: { @@ -431,6 +436,7 @@ size: 0 }, (error, response) => { if (error) { + error.stack += previousError.stack; return reject(error); } return resolve(response.aggregations.intraday_return.value); @@ -440,7 +446,7 @@ groupBy(field, args = {}) { return new Promise((resolve, reject) => { - var allFields, dbField, property, propertyName, queryObject, ref, ref1, ref2, ref3, ref4; + var allFields, dbField, previousError, property, propertyName, queryObject, ref, ref1, ref2, ref3, ref4; /* Aggregations http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations.html @@ -481,6 +487,7 @@ if (queryObject.isContainsEmpty) { return resolve([]); } + previousError = new Error('From previous stack'); return this.documentClass._es.search({ index: this.documentClass.getIndexName(), body: { @@ -500,6 +507,7 @@ size: 0 }, (error, response) => { if (error) { + error.stack += previousError.stack; return reject(error); } return resolve(response.aggregations.genres.buckets); diff --git a/package.json b/package.json index e1444af..058d5dc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "enju", - "version": "5.1.2", + "version": "5.2.0", "description": "An elasticsearch client on node.js written in CoffeeScript.", "main": "index.js", "scripts": {