Skip to content

Error Handling for null Params to Client.prototype.query() #1651

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,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
Original file line number Diff line number Diff line change
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')
}
})
})
})