Avoid the release of Zalgo (#1295)
This commit is contained in:
committed by
GitHub
parent
96a54d0539
commit
7f317d3321
@ -139,14 +139,28 @@ class Transport {
|
||||
? 0 : (typeof options.maxRetries === 'number' ? options.maxRetries : this.maxRetries)
|
||||
const compression = options.compression !== undefined ? options.compression : this.compression
|
||||
var request = { abort: noop }
|
||||
const transportReturn = {
|
||||
then (onFulfilled, onRejected) {
|
||||
return p.then(onFulfilled, onRejected)
|
||||
},
|
||||
catch (onRejected) {
|
||||
return p.catch(onRejected)
|
||||
},
|
||||
abort () {
|
||||
meta.aborted = true
|
||||
request.abort()
|
||||
debug('Aborting request', params)
|
||||
return this
|
||||
}
|
||||
}
|
||||
|
||||
const makeRequest = () => {
|
||||
if (meta.aborted === true) {
|
||||
return callback(new RequestAbortedError(), result)
|
||||
return process.nextTick(callback, new RequestAbortedError(), result)
|
||||
}
|
||||
meta.connection = this.getConnection({ requestId: meta.request.id })
|
||||
if (meta.connection == null) {
|
||||
return callback(new NoLivingConnectionsError(), result)
|
||||
return process.nextTick(callback, new NoLivingConnectionsError(), result)
|
||||
}
|
||||
this.emit('request', null, result)
|
||||
// perform the actual http request
|
||||
@ -281,7 +295,8 @@ class Transport {
|
||||
try {
|
||||
params.body = this.serializer.serialize(params.body)
|
||||
} catch (err) {
|
||||
return callback(err, result)
|
||||
process.nextTick(callback, err, result)
|
||||
return transportReturn
|
||||
}
|
||||
}
|
||||
|
||||
@ -295,7 +310,8 @@ class Transport {
|
||||
try {
|
||||
params.body = this.serializer.ndserialize(params.bulkBody)
|
||||
} catch (err) {
|
||||
return callback(err, result)
|
||||
process.nextTick(callback, err, result)
|
||||
return transportReturn
|
||||
}
|
||||
} else {
|
||||
params.body = params.bulkBody
|
||||
@ -348,20 +364,7 @@ class Transport {
|
||||
makeRequest()
|
||||
}
|
||||
|
||||
return {
|
||||
then (onFulfilled, onRejected) {
|
||||
return p.then(onFulfilled, onRejected)
|
||||
},
|
||||
catch (onRejected) {
|
||||
return p.catch(onRejected)
|
||||
},
|
||||
abort () {
|
||||
meta.aborted = true
|
||||
request.abort()
|
||||
debug('Aborting request', params)
|
||||
return this
|
||||
}
|
||||
}
|
||||
return transportReturn
|
||||
}
|
||||
|
||||
getConnection (opts) {
|
||||
|
||||
Reference in New Issue
Block a user