Commit 4dc98af4 by Ben Drucker

Wrap #find calls in Promise.method so assert failures become rejections

parent 21ac2cfc
'use strict'; 'use strict';
var assert = require('assert'); var assert = require('assert');
var _ = require('lodash'); var _ = require('lodash');
var Promise = require('bluebird');
module.exports = function (client) { module.exports = function (client) {
function Company (data) { function Company (data) {
...@@ -12,7 +13,7 @@ module.exports = function (client) { ...@@ -12,7 +13,7 @@ module.exports = function (client) {
return !this.id; return !this.id;
}; };
Company.find = function (options) { Company.find = Promise.method(function (options) {
assert(options && options.domain, 'A domain must be provided'); assert(options && options.domain, 'A domain must be provided');
return this.client.request(_.extend({ return this.client.request(_.extend({
api: 'company', api: 'company',
...@@ -22,7 +23,7 @@ module.exports = function (client) { ...@@ -22,7 +23,7 @@ module.exports = function (client) {
.then(function (data) { .then(function (data) {
return new this(data); return new this(data);
}); });
}; });
Company.prototype.client = Company.client = client; Company.prototype.client = Company.client = client;
......
'use strict'; 'use strict';
var assert = require('assert'); var assert = require('assert');
var _ = require('lodash'); var _ = require('lodash');
var Promise = require('bluebird');
module.exports = function (client) { module.exports = function (client) {
function Person (data) { function Person (data) {
...@@ -12,7 +13,7 @@ module.exports = function (client) { ...@@ -12,7 +13,7 @@ module.exports = function (client) {
return !this.id; return !this.id;
}; };
Person.find = function (options) { Person.find = Promise.method(function (options) {
assert(options && options.email, 'An email must be provided'); assert(options && options.email, 'An email must be provided');
return this.client.request(_.extend({ return this.client.request(_.extend({
api: 'person', api: 'person',
...@@ -23,9 +24,9 @@ module.exports = function (client) { ...@@ -23,9 +24,9 @@ module.exports = function (client) {
.then(function (data) { .then(function (data) {
return new this(data); return new this(data);
}); });
}; });
Person.prototype.client = Person.client = client; Person.prototype.client = Person.client = client;
return Person; return Person;
}; };
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment