Small fixes
This commit is contained in:
@ -20,7 +20,7 @@ class Connection {
|
|||||||
|
|
||||||
this._openRequests = 0
|
this._openRequests = 0
|
||||||
this._status = opts.status || Connection.statuses.ALIVE
|
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)) {
|
if (!['http:', 'https:'].includes(this.url.protocol)) {
|
||||||
throw new ConfigurationError(`Invalid protocol: '${this.url.protocol}'`)
|
throw new ConfigurationError(`Invalid protocol: '${this.url.protocol}'`)
|
||||||
@ -104,6 +104,7 @@ class Connection {
|
|||||||
// starts the request
|
// starts the request
|
||||||
if (isStream(params.body) === true) {
|
if (isStream(params.body) === true) {
|
||||||
pump(params.body, request, err => {
|
pump(params.body, request, err => {
|
||||||
|
/* istanbul ignore if */
|
||||||
if (err != null && ended === false) {
|
if (err != null && ended === false) {
|
||||||
ended = true
|
ended = true
|
||||||
this._openRequests--
|
this._openRequests--
|
||||||
@ -129,14 +130,13 @@ class Connection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setRole (role, enabled) {
|
setRole (role, enabled) {
|
||||||
assert(
|
if (validRoles.indexOf(role) === -1) {
|
||||||
~validRoles.indexOf(role),
|
throw new ConfigurationError(`Unsupported role: '${role}'`)
|
||||||
`Unsupported role: '${role}'`
|
}
|
||||||
)
|
if (typeof enabled !== 'boolean') {
|
||||||
assert(
|
throw new ConfigurationError('enabled should be a boolean')
|
||||||
typeof enabled === 'boolean',
|
}
|
||||||
'enabled should be a boolean'
|
|
||||||
)
|
|
||||||
this.roles[role] = enabled
|
this.roles[role] = enabled
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|||||||
@ -185,6 +185,7 @@ class Transport {
|
|||||||
// collect the payload
|
// collect the payload
|
||||||
response.setEncoding('utf8')
|
response.setEncoding('utf8')
|
||||||
response.on('data', chunk => { payload += chunk })
|
response.on('data', chunk => { payload += chunk })
|
||||||
|
/* istanbul ignore next */
|
||||||
response.on('error', err => {
|
response.on('error', err => {
|
||||||
const error = new ConnectionError(err.message, params)
|
const error = new ConnectionError(err.message, params)
|
||||||
this.emit('response', error, meta)
|
this.emit('response', error, meta)
|
||||||
|
|||||||
Reference in New Issue
Block a user