Add error handling for null params to Client.prototype.query()

This commit is contained in:
Pat Gaffney 2018-06-19 19:17:13 -05:00 committed by Brian C
parent e7602bc678
commit 11a4793452
2 changed files with 24 additions and 1 deletions

View File

@ -352,7 +352,10 @@ Client.prototype.query = function (config, values, callback) {
// can take in strings, config object or query object
var query
var result
if (typeof config.submit === 'function') {
if (config === null || config === undefined) {
throw new TypeError('Client was passed a null or undefined query')
} else if (typeof config.submit === 'function') {
result = query = config
if (typeof values === 'function') {
query.callback = query.callback || values

View File

@ -120,4 +120,24 @@ test('executing query', function () {
})
})
})
test('handles errors', function () {
var client = helper.client()
test('throws an error when config is null', function () {
try {
client.query(null, undefined)
} catch (error) {
assert.equal(error.message, 'Client was passed a null or undefined query', 'Should have thrown an Error for null queries')
}
})
test('throws an error when config is undefined', function () {
try {
client.query()
} catch (error) {
assert.equal(error.message, 'Client was passed a null or undefined query', 'Should have thrown an Error for null queries')
}
})
})
})