Skip to content

Instantly share code, notes, and snippets.

@AdriVanHoudt
Created December 29, 2015 13:26
Show Gist options
  • Save AdriVanHoudt/1b8ceddda73020b2dc1c to your computer and use it in GitHub Desktop.
Save AdriVanHoudt/1b8ceddda73020b2dc1c to your computer and use it in GitHub Desktop.

Revisions

  1. AdriVanHoudt renamed this gist Dec 29, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. AdriVanHoudt created this gist Dec 29, 2015.
    45 changes: 45 additions & 0 deletions example.gist
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    // error happens because of https://github.com/AdriVanHoudt/Hapi-Boombox/blob/master/lib/index.js#L42

    exports.getAll = function (request, reply) {

    return Entity.getAll(request.auth.credentials.team, dbConn, (err, result) => {

    if (err) {
    return reply(err);
    }

    return Async.map(result, (item, callback) => {

    if (item.id) {
    return Entity.getSubStuff(item.id, dbConn, (err, stuff) => {

    if (err) {
    return callback(err);
    }

    item.stuff = stuff;

    // 3: getSubStuff is done after reply with error and calls callback
    return callback(null, item);
    });
    }

    return Entity.getOtherStuff(request.auth.credentials.team, dbConn, (err, otherStuff) => {

    if (err) {
    // 1: errors
    return callback(err);
    }

    item.stuff = otherStuff;

    return callback(null, item);
    });
    }, (err, results) => {

    // 2: call reply with error
    // 4: reply gets called again
    return reply(err, results);
    });
    });
    };