Commit 4dc98af4 by Ben Drucker

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

parent 21ac2cfc
......@@ -2,6 +2,7 @@
var assert = require('assert');
var _ = require('lodash');
var Promise = require('bluebird');
module.exports = function (client) {
function Company (data) {
......@@ -12,7 +13,7 @@ module.exports = function (client) {
return !this.id;
};
Company.find = function (options) {
Company.find = Promise.method(function (options) {
assert(options && options.domain, 'A domain must be provided');
return this.client.request(_.extend({
api: 'company',
......@@ -22,7 +23,7 @@ module.exports = function (client) {
.then(function (data) {
return new this(data);
});
};
});
Company.prototype.client = Company.client = client;
......
......@@ -2,6 +2,7 @@
var assert = require('assert');
var _ = require('lodash');
var Promise = require('bluebird');
module.exports = function (client) {
function Person (data) {
......@@ -12,7 +13,7 @@ module.exports = function (client) {
return !this.id;
};
Person.find = function (options) {
Person.find = Promise.method(function (options) {
assert(options && options.email, 'An email must be provided');
return this.client.request(_.extend({
api: 'person',
......@@ -23,7 +24,7 @@ module.exports = function (client) {
.then(function (data) {
return new this(data);
});
};
});
Person.prototype.client = Person.client = client;
......
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