Permalink
Browse files

better error handling in case of an empty res.SelectResult

  • Loading branch information...
1 parent c7ab99c commit 6f949c2d5886301152702ab1ac5846b0c5a7a39a @tracend tracend committed May 29, 2013
Showing with 12 additions and 4 deletions.
  1. +12 −4 lib/simpledb.js
View
@@ -120,7 +120,7 @@ exports.SimpleDB = function(opts,logger) {
awsopts.port = null == opts.port ? 80 : opts.port
awsopts.nolimit = null == opts.nolimit ? false : opts.nolimit
awsopts.maxlimit= 2500 // this is set by the AWS service: http://docs.aws.amazon.com/AmazonSimpleDB/latest/DeveloperGuide/SDBLimits.html
-
+ // container to aggregate results of the select queries over maxlimit
var results = []
log('create',opts,awsopts)
@@ -152,16 +152,24 @@ exports.SimpleDB = function(opts,logger) {
}
if( !err ) {
- results = results.concat( res.SelectResult.Item )
+ // save new results
+ if( res.SelectResult ) results = results.concat( res.SelectResult.Item )
+ // check if we've achieved the max number of results
+ var maxcount = false;
+ try {
+ maxcount = ( res.SelectResult.Item.length == awsopts.maxlimit )
+ } catch( e ){
+ // nothing to do...
+ }
// optionally make subsequent requests for queries over the max limit
- if( awsopts.nolimit && res.SelectResult.Item && ( res.SelectResult.Item.length == awsopts.maxlimit ) && res.SelectResult.NextToken){
+ if( awsopts.nolimit && maxcount && res.SelectResult.NextToken){
// get the next batch of results
q.NextToken = res.SelectResult.NextToken
makereq(act,q,callback)
} else {
stop(true)
// replacing with aggregated results only if nolimit is set
- if( awsopts.nolimit ) res.SelectResult.Item = results
+ if( awsopts.nolimit && res.SelectResult ) res.SelectResult.Item = results
callback(err,res,meta)
}
}

0 comments on commit 6f949c2

Please sign in to comment.