mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Intercept response status code in tpds worker and catch errors before proxying
This commit is contained in:
parent
6f2b7e43a6
commit
8146dd7ce9
1 changed files with 17 additions and 13 deletions
|
@ -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)->
|
||||||
|
|
Loading…
Reference in a new issue