Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add error handling for null params to Client.prototype.query()
  • Loading branch information
patrickrgaffney authored and brianc committed Oct 3, 2018
1 parent e7602bc commit 11a4793
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/client.js
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions test/unit/client/simple-query-tests.js
Expand Up @@ -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')
}
})
})
})

0 comments on commit 11a4793

Please sign in to comment.