Skip to content

Commit 11a4793

Browse files
patrickrgaffneybrianc
authored andcommittedOct 3, 2018
Add error handling for null params to Client.prototype.query()
1 parent e7602bc commit 11a4793

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed
 

‎lib/client.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,10 @@ Client.prototype.query = function (config, values, callback) {
352352
// can take in strings, config object or query object
353353
var query
354354
var result
355-
if (typeof config.submit === 'function') {
355+
356+
if (config === null || config === undefined) {
357+
throw new TypeError('Client was passed a null or undefined query')
358+
} else if (typeof config.submit === 'function') {
356359
result = query = config
357360
if (typeof values === 'function') {
358361
query.callback = query.callback || values

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

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

0 commit comments

Comments
 (0)
Please sign in to comment.