then/then-request

Not working with 'sepia'

rstacruz opened this issue · 4 comments

It'd be nice to have then-request work with sepia.

For now, this is what happens:

/···/node_modules/sepia/src/cache.js:130
          callback(res);
          ^
TypeError: undefined is not a function
    at /···/node_modules/then-request/index.js:73:16
    at /···/node_modules/then-request/node_modules/http-basic/index.js:84:14
    at /···/node_modules/then-request/node_modules/http-basic/index.js:126:16
    at /···/node_modules/then-request/node_modules/http-basic/index.js:232:5
    at playback (/···/node_modules/sepia/src/cache.js:130:11)
    at EventEmitter.req.end (/···/node_modules/sepia/src/cache.js:145:9)
    at request (/···/node_modules/then-request/node_modules/http-basic/index.js:259:9)
    at request (/···/node_modules/then-request/node_modules/http-basic/index.js:88:12)
    at /···/node_modules/then-request/node_modules/http-basic/index.js:124:16
    at /···/node_modules/then-request/node_modules/http-basic/index.js:232:5
    at playback (/···/node_modules/sepia/src/cache.js:130:11)
    at EventEmitter.req.end (/···/node_modules/sepia/src/cache.js:145:9)
    at request (/···/node_modules/then-request/node_modules/http-basic/index.js:259:9)
    at request (/···/node_modules/then-request/node_modules/http-basic/index.js:88:12)
    at Function.request (/···/node_modules/then-request/node_modules/http-basic/index.js:63:12)
    at /···/node_modules/then-request/index.js:59:30

I'm confused. That error doesn't even look like its thrown by then-request. It looks like a bug in sepia

this part:

/···/node_modules/sepia/src/cache.js:130
          callback(res);
          ^
TypeError: undefined is not a function

...says sepia tried to invoke a callback function (presumably one provided by then-request) that raised an error. ie, if you change that line in Sepia from callback(err) to try { callback(err) } catch(e) { ... }, you'd catch the error.

okay, investigating further, then-request accesses res.body.pipe(...), and sepia doesn't provide a .pipe() in the res.body.

Node.js calls the callback with a stream as the response object. That stream has a .pipe method (all node.js streams do). http-basic then puts that stream as the value of res.body. If sepia breaks the node.js request API, then sepia needs fixing rather than then-request.