Skip to content

Commit

Permalink
.models throws error and Deferreds reject on exceptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl committed Jul 24, 2013
1 parent 8442d73 commit 1dfc161
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
12 changes: 10 additions & 2 deletions model/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ steal('can/util','can/observe', function( can ) {
var d = new can.Deferred();
def.then(function(){
var args = can.makeArray( arguments );
args[0] = model[func](args[0]);
d.resolveWith(d, args);
try {
args[0] = model[func](args[0]);
d.resolveWith(d, args);
} catch(e) {
d.rejectWith(d, [e].concat(args));
}
},function(){
d.rejectWith(this, arguments);
});
Expand Down Expand Up @@ -928,6 +932,10 @@ steal('can/util','can/observe', function( can ) {
instancesRawData.data),
i = 0;

if(typeof raw === 'undefined') {
throw new Error('Could not get any raw data while converting using .models');
}

//!steal-remove-start
if ( ! raw.length ) {
steal.dev.warn("model.js models has no data.")
Expand Down
23 changes: 23 additions & 0 deletions model/model_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,29 @@ test("findAll deferred", function(){
})
});

test("findAll rejects non-array (#384)", function() {
var Person = can.Model({
findAll : function(params, success, error){
var dfd = can.Deferred();
setTimeout(function() {
dfd.resolve({
stuff: {}
});
}, 100);
return dfd;
}
},{});

stop();
Person.findAll({}).then(function() {
ok(false, 'This should not succeed');
}, function(err) {
ok(err instanceof Error, 'Got an error');
equal(err.message, 'Could not get any raw data while converting using .models');
start();
});
});

asyncTest("findAll deferred reject", function() {
// This test is automatically paused

Expand Down

0 comments on commit 1dfc161

Please sign in to comment.