Co-authored-by: Tomas Della Vedova <delvedor@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
c9808fb067
commit
4441de678f
@ -306,8 +306,8 @@ class Transport {
|
|||||||
return callback(err, result)
|
return callback(err, result)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// cast to boolean if the request method was HEAD
|
// cast to boolean if the request method was HEAD and there was no error
|
||||||
result.body = isHead === true ? true : payload
|
result.body = isHead === true && result.statusCode < 400 ? true : payload
|
||||||
}
|
}
|
||||||
|
|
||||||
// we should ignore the statusCode if the user has configured the `ignore` field with
|
// we should ignore the statusCode if the user has configured the `ignore` field with
|
||||||
|
|||||||
@ -1613,7 +1613,7 @@ test('Should cast to boolean HEAD request', t => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.test('4xx response', t => {
|
t.test('4xx response', t => {
|
||||||
t.plan(2)
|
t.plan(3)
|
||||||
|
|
||||||
const pool = new ConnectionPool({ Connection: MockConnection })
|
const pool = new ConnectionPool({ Connection: MockConnection })
|
||||||
pool.addConnection('http://localhost:9200')
|
pool.addConnection('http://localhost:9200')
|
||||||
@ -1633,12 +1633,13 @@ test('Should cast to boolean HEAD request', t => {
|
|||||||
path: '/400'
|
path: '/400'
|
||||||
}, (err, { body, statusCode }) => {
|
}, (err, { body, statusCode }) => {
|
||||||
t.ok(err instanceof ResponseError)
|
t.ok(err instanceof ResponseError)
|
||||||
|
t.false(typeof err.body === 'boolean')
|
||||||
t.strictEqual(statusCode, 400)
|
t.strictEqual(statusCode, 400)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
t.test('5xx response', t => {
|
t.test('5xx response', t => {
|
||||||
t.plan(2)
|
t.plan(3)
|
||||||
const pool = new ConnectionPool({ Connection: MockConnection })
|
const pool = new ConnectionPool({ Connection: MockConnection })
|
||||||
pool.addConnection('http://localhost:9200')
|
pool.addConnection('http://localhost:9200')
|
||||||
|
|
||||||
@ -1657,6 +1658,7 @@ test('Should cast to boolean HEAD request', t => {
|
|||||||
path: '/500'
|
path: '/500'
|
||||||
}, (err, { body, statusCode }) => {
|
}, (err, { body, statusCode }) => {
|
||||||
t.ok(err instanceof ResponseError)
|
t.ok(err instanceof ResponseError)
|
||||||
|
t.false(typeof err.body === 'boolean')
|
||||||
t.strictEqual(statusCode, 500)
|
t.strictEqual(statusCode, 500)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user