Skip to content

Commit

Permalink
Merge pull request #90 from Medium/nicks/error
Browse files Browse the repository at this point in the history
Fix a bug in error handing for queries
  • Loading branch information
nicks committed Jun 1, 2016
2 parents cd54276 + 25ee14a commit 45a3b7e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/QueryBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ QueryBuilder.prototype.execute = function () {
return this.request('query', queryData)
.then(this.prepareOutput.bind(this))
.fail(this.emptyResults)
.failBound(this.convertErrors, null, {attributes: queryData, isWrite: false})
.failBound(this.convertErrors, null, {data: queryData, isWrite: false})
}

module.exports = QueryBuilder
11 changes: 6 additions & 5 deletions lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ var util = require('util')
*/
function ConditionalError(data, msg) {
Error.captureStackTrace(this)
this.data = data
this.data = data || {}
this.message = 'The conditional request failed'
this.details = msg
this.table = data.TableName
this.table = data.TableName || 'unknown'
}
util.inherits(ConditionalError, Error)
ConditionalError.prototype.type = 'ConditionalError'
Expand All @@ -29,10 +29,10 @@ ConditionalError.prototype.name = 'ConditionalError'
*/
function ProvisioningError(data, msg, isWrite) {
Error.captureStackTrace(this)
this.data = data
this.data = data || {}
this.message = 'The level of configured provisioned throughput for the table was exceeded'
this.details = msg
this.table = data.TableName
this.table = data.TableName || 'unknown'
this.isWrite = isWrite
}
util.inherits(ProvisioningError, Error)
Expand All @@ -49,8 +49,9 @@ ProvisioningError.prototype.name = 'ProvisioningError'
*/
function ValidationError(data, msg, isWrite) {
Error.captureStackTrace(this)
this.data = data
this.data = data || {}
this.message = msg
this.table = data.TableName || 'unknown'
this.isWrite = isWrite
}
util.inherits(ValidationError, Error)
Expand Down
14 changes: 14 additions & 0 deletions test/testQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,3 +332,17 @@ builder.add(function testNextWithLimit(test) {
if (e.message !== 'No more results') throw e
})
})

builder.add(function testValidationError(test) {
var client = this.client
return client.newQueryBuilder('comments')
.setHashKey('garbage', 'postId')
.execute()
.then(function (x) {
test.fail('Expected validation exception')
})
.fail(function (e) {
if (!client.isValidationError(e)) throw e
test.equal('comments', e.table)
})
})

0 comments on commit 45a3b7e

Please sign in to comment.