diff --git a/services/web/TpdsWorker.coffee b/services/web/TpdsWorker.coffee index 5ffc1e303d..ba982ac2d5 100644 --- a/services/web/TpdsWorker.coffee +++ b/services/web/TpdsWorker.coffee @@ -38,21 +38,25 @@ processingFuncs = request options.streamOrigin, (err,res, body)-> logger.log options:options, body:body 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)-> logger.error err:err, options:options, "something went wrong in pipeStreamFrom origin" - if 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 + callback(err) + workerRegistration = (groupKey, method, options, callback)->