Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d11926b

Browse files
committedJun 19, 2018
Add error handling for null params to Client.prototype.query()
1 parent 3ac356a commit d11926b

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed
 

‎lib/client.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,10 @@ Client.prototype.query = function (config, values, callback) {
365365
// can take in strings, config object or query object
366366
var query
367367
var result
368-
if (typeof config.submit === 'function') {
368+
369+
if (config === null || config === undefined) {
370+
throw new TypeError('Client was passed a null or undefined query')
371+
} else if (typeof config.submit === 'function') {
369372
result = query = config
370373
if (typeof values === 'function') {
371374
query.callback = query.callback || values

‎test/unit/client/simple-query-tests.js

+21
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,25 @@ test('executing query', function () {
120120
})
121121
})
122122
})
123+
124+
test('handles errors', function () {
125+
var client = helper.client()
126+
var error = new Error('Client was passed a null or undefined query')
127+
128+
test('throws an error when config is null', function () {
129+
try {
130+
client.query(null, undefined)
131+
} catch (error) {
132+
assert.equal(error.message, 'Client was passed a null or undefined query', 'Should have thrown an Error for null queries')
133+
}
134+
})
135+
136+
test('throws an error when config is undefined', function () {
137+
try {
138+
client.query()
139+
} catch (error) {
140+
assert.equal(error.message, 'Client was passed a null or undefined query', 'Should have thrown an Error for null queries')
141+
}
142+
})
143+
})
123144
})

0 commit comments

Comments
 (0)
Please sign in to comment.