Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/v1/internal/connection-holder.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default class ConnectionHolder {

/**
* Notify this holder that single party does not require current connection any more.
* @return {Promise<Connection>} promise resolved with the current connection.
* @return {Promise<Connection>} promise resolved with the current connection, never a rejected promise.
*/
releaseConnection() {
if (this._referenceCount === 0) {
Expand Down
17 changes: 10 additions & 7 deletions src/v1/result.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
import ResultSummary from './result-summary';
import {EMPTY_CONNECTION_HOLDER} from './internal/connection-holder';

const DEFAULT_ON_ERROR = error => {
console.log('Uncaught error when processing result: ' + error);
};
const DEFAULT_ON_COMPLETED = summary => {
};

/**
* A stream of {@link Record} representing the result of a statement.
* @access public
Expand Down Expand Up @@ -102,12 +108,12 @@ class Result {
* @return
*/
subscribe(observer) {
const onCompletedOriginal = observer.onCompleted;
const self = this;
const onCompletedWrapper = (metadata) => {

const onCompletedOriginal = observer.onCompleted || DEFAULT_ON_COMPLETED;
const onCompletedWrapper = (metadata) => {
const additionalMeta = self._metaSupplier();
for(let key in additionalMeta) {
for (let key in additionalMeta) {
if (additionalMeta.hasOwnProperty(key)) {
metadata[key] = additionalMeta[key];
}
Expand All @@ -122,10 +128,7 @@ class Result {
};
observer.onCompleted = onCompletedWrapper;

const onErrorOriginal = observer.onError || (error => {
console.log("Uncaught error when processing result: " + error);
});

const onErrorOriginal = observer.onError || DEFAULT_ON_ERROR;
const onErrorWrapper = error => {
// notify connection holder that the used connection is not needed any more because error happened
// and result can't bee consumed any further; call the original onError callback after that
Expand Down
12 changes: 12 additions & 0 deletions test/v1/result.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,16 @@ describe('result stream', () => {
done()
});
});

it('should handle missing onCompleted', done => {
session.run('RETURN 1').subscribe({
onNext: record => {
expect(record.get(0).toInt()).toEqual(1);
done();
},
onError: error => {
console.log(error);
}
});
});
});