File tree Expand file tree Collapse file tree 4 files changed +20
-14
lines changed
Expand file tree Collapse file tree 4 files changed +20
-14
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 /**
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ const redis = require("redis");
1111
1212
1313// own modules
14+ const errors = require ( "../lib/errors" ) ;
1415const 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 ( ) ;
You can’t perform that action at this time.
0 commit comments