Small fixes

This commit is contained in:
delvedor
2019-02-11 17:37:29 +01:00
parent dbe4557848
commit ecb2ba47a8
2 changed files with 10 additions and 9 deletions

View File

@ -20,7 +20,7 @@ class Connection {
this._openRequests = 0
this._status = opts.status || Connection.statuses.ALIVE
this.roles = Object.assign({}, defaultRoles, opts.roles) || Object.assign({}, defaultRoles)
this.roles = Object.assign({}, defaultRoles, opts.roles)
if (!['http:', 'https:'].includes(this.url.protocol)) {
throw new ConfigurationError(`Invalid protocol: '${this.url.protocol}'`)
@ -104,6 +104,7 @@ class Connection {
// starts the request
if (isStream(params.body) === true) {
pump(params.body, request, err => {
/* istanbul ignore if */
if (err != null && ended === false) {
ended = true
this._openRequests--
@ -129,14 +130,13 @@ class Connection {
}
setRole (role, enabled) {
assert(
~validRoles.indexOf(role),
`Unsupported role: '${role}'`
)
assert(
typeof enabled === 'boolean',
'enabled should be a boolean'
)
if (validRoles.indexOf(role) === -1) {
throw new ConfigurationError(`Unsupported role: '${role}'`)
}
if (typeof enabled !== 'boolean') {
throw new ConfigurationError('enabled should be a boolean')
}
this.roles[role] = enabled
return this
}

View File

@ -185,6 +185,7 @@ class Transport {
// collect the payload
response.setEncoding('utf8')
response.on('data', chunk => { payload += chunk })
/* istanbul ignore next */
response.on('error', err => {
const error = new ConnectionError(err.message, params)
this.emit('response', error, meta)