mirror of
https://github.com/brianc/node-postgres.git
synced 2026-01-18 15:55:05 +00:00
Add error handling for null params to Client.prototype.query()
This commit is contained in:
parent
e7602bc678
commit
11a4793452
@ -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
|
||||
|
||||
@ -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')
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user