chore(Xapi#_transportCall): simplify and improve code

It may even fixes some issues.
This commit is contained in:
Julien Fontanet 2016-08-15 16:33:07 +02:00
parent 59d9b3c6b4
commit ab6b1e2c32

View File

@ -418,8 +418,9 @@ export class Xapi extends EventEmitter {
} }
// Low level call: handle transport errors. // Low level call: handle transport errors.
_transportCall (method, args, startTime = Date.now(), tries = 1) { _transportCall (method, args) {
return this._rawCall(method, args) let tries = 1
const loop = () => this._rawCall(method, args)
::pCatch(isNetworkError, isXapiNetworkError, error => { ::pCatch(isNetworkError, isXapiNetworkError, error => {
debug('%s: network error %s', this._humanId, error.code) debug('%s: network error %s', this._humanId, error.code)
@ -447,28 +448,30 @@ export class Xapi extends EventEmitter {
return this._transportCall(method, args, startTime) return this._transportCall(method, args, startTime)
}) })
.then(
result => { const startTime = Date.now()
debug( return loop().then(
'%s: %s(...) [%s] ==> %s', result => {
this._humanId, debug(
method, '%s: %s(...) [%s] ==> %s',
ms(Date.now() - startTime), this._humanId,
kindOf(result) method,
) ms(Date.now() - startTime),
return result kindOf(result)
}, )
error => { return result
debug( },
'%s: %s(...) [%s] =!> %s', error => {
this._humanId, debug(
method, '%s: %s(...) [%s] =!> %s',
ms(Date.now() - startTime), this._humanId,
error method,
) ms(Date.now() - startTime),
throw error error
} )
) throw error
}
)
} }
// Lowest level call: do not handle any errors. // Lowest level call: do not handle any errors.