Intercept response status code in tpds worker and catch errors before proxying

This commit is contained in:
James Allen 2014-03-25 21:43:42 +00:00
parent 6f2b7e43a6
commit 8146dd7ce9

View file

@ -38,21 +38,25 @@ processingFuncs =
request options.streamOrigin, (err,res, body)-> request options.streamOrigin, (err,res, body)->
logger.log options:options, body:body logger.log options:options, body:body
origin = request(options.streamOrigin) origin = request(options.streamOrigin)
origin.on 'response', (res) ->
if 200 <= res.statusCode < 300
dest = request(options)
origin.pipe(dest)
dest.on "error", (err)->
logger.error err:err, options:options, "something went wrong in pipeStreamFrom dest"
callback(err)
dest.on 'end', callback
else
error = new Error("received non-success status code: #{res.statusCode}")
logger.error err: error, options: options, "something went wrong connecting to origin"
callback(error)
origin.on 'error', (err)-> origin.on 'error', (err)->
logger.error err:err, options:options, "something went wrong in pipeStreamFrom origin" logger.error err:err, options:options, "something went wrong in pipeStreamFrom origin"
if err? callback(err)
callback(err)
else
callback()
dest = request(options)
origin.pipe(dest)
dest.on "error", (err)->
logger.error err:err, options:options, "something went wrong in pipeStreamFrom dest"
if err?
callback(err)
else
callback()
dest.on 'end', callback
workerRegistration = (groupKey, method, options, callback)-> workerRegistration = (groupKey, method, options, callback)->