Skip to content

Commit 2bc1ec2

Browse files
committed
fix: minor fixes
1 parent 2d33941 commit 2bc1ec2

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed

lib/form.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,11 @@ class Form extends EventEmitter {
5858
const event = "done";
5959
if (this.listenerCount(event)) {
6060
debug("emitting done event");
61-
// TODO: Don't return here!
62-
return this.emit(event, formset, answers, ref);
61+
this.emit(event, formset, answers, ref);
6362
}
6463
if (this.options.cb) {
6564
debug("firing form callback");
66-
// TODO: Await cb!
67-
this.options.cb(answers, ref);
65+
await this.options.cb(answers, ref);
6866
}
6967
}
7068

lib/formset.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ class FormSet extends EventEmitter {
7979
return this._forms;
8080
}
8181

82-
// TODO: i18n should also use promises!
83-
8482
/**
8583
* Add a new form to this set.
8684
* @param {String} name Name of the form e.g. "profile"
@@ -254,7 +252,7 @@ class FormSet extends EventEmitter {
254252
throw new errors.SessionError(error);
255253
}
256254

257-
this.emit("query", question, ref);
255+
this._emitQuery(question, ref);
258256
}
259257

260258
/**
@@ -273,6 +271,15 @@ class FormSet extends EventEmitter {
273271
throw new errors.SessionError(error);
274272
}
275273
}
274+
275+
/**
276+
* Emits the `query` event.
277+
* @param {Object} question Query
278+
* @param {Object} ref Reference
279+
*/
280+
_emitQuery(question, ref) {
281+
this.emit("query", question, ref);
282+
}
276283
}
277284

278285

lib/query-controller.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,7 @@ class QueryController {
174174
*/
175175
async advance(answer) {
176176
debug("advancing on queries: current-index=%d", this._index);
177-
// TODO: Assert answer is a string!
178-
assert.ok(answer || answer === null, "Answer must be provided.");
177+
assert.ok(typeof answer === "string" || answer === null, "Answer must be provided.");
179178

180179
if (this.currentQuery) {
181180
debug("found current query");
@@ -423,9 +422,7 @@ class QueryController {
423422
async send(id) {
424423
debug("sending text message: %s", id);
425424
const text = await this.text(id, this.getAnswers());
426-
// TODO: pass callback to `query` event
427-
// TODO: Refactor to use a formset method instead.
428-
this.formset.emit("query", { text }, this.ref);
425+
this.formset._emitQuery({ text }, this.ref);
429426
}
430427

431428
/**

store/redis.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const redis = require("redis");
1111

1212

1313
// own modules
14+
const errors = require("../lib/errors");
1415
const SessionStore = require("./base");
1516

1617

@@ -44,8 +45,11 @@ class RedisSessionStore extends SessionStore {
4445
if (!data) {
4546
return null;
4647
}
47-
// TODO: Throw proper error if parsing fails.
48-
return JSON.parse(data);
48+
try {
49+
return JSON.parse(data);
50+
} catch (error) {
51+
throw new errors.SessionError(error);
52+
}
4953
}
5054
async put(sid, session, options) {
5155
await this._connect();

0 commit comments

Comments
 (0)