Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
clearbit
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
prospector
clearbit
Commits
459918e8
Commit
459918e8
authored
Oct 10, 2014
by
Ben Drucker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle resource not found errors
parent
2fd40770
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
11 deletions
+54
-11
company.js
src/company.js
+6
-5
person.js
src/person.js
+6
-5
utils.js
src/utils.js
+17
-0
company.js
test/company.js
+12
-0
person.js
test/person.js
+13
-1
No files found.
src/company.js
View file @
459918e8
...
@@ -3,15 +3,14 @@
...
@@ -3,15 +3,14 @@
var
assert
=
require
(
'assert'
);
var
assert
=
require
(
'assert'
);
var
_
=
require
(
'lodash'
);
var
_
=
require
(
'lodash'
);
var
Promise
=
require
(
'bluebird'
);
var
Promise
=
require
(
'bluebird'
);
var
utils
=
require
(
'./utils'
);
module
.
exports
=
function
(
client
)
{
module
.
exports
=
function
(
client
)
{
function
Company
(
data
)
{
function
Company
(
data
)
{
_
.
extend
(
this
,
data
);
_
.
extend
(
this
,
data
);
}
}
Company
.
prototype
.
pending
=
function
()
{
Company
.
prototype
.
pending
=
utils
.
pending
;
return
!
this
.
id
;
};
Company
.
find
=
Promise
.
method
(
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'
);
...
@@ -20,12 +19,14 @@ module.exports = function (client) {
...
@@ -20,12 +19,14 @@ module.exports = function (client) {
path
:
'/companies/domain/'
+
options
.
domain
path
:
'/companies/domain/'
+
options
.
domain
},
options
))
},
options
))
.
bind
(
this
)
.
bind
(
this
)
.
then
(
function
(
data
)
{
.
then
(
utils
.
cast
)
return
new
this
(
data
);
.
catch
(
utils
.
isUnknownRecord
,
function
(
err
)
{
throw
new
this
.
NotFoundError
(
'Company not found'
);
});
});
});
});
Company
.
prototype
.
client
=
Company
.
client
=
client
;
Company
.
prototype
.
client
=
Company
.
client
=
client
;
Company
.
NotFoundError
=
utils
.
NotFoundError
;
return
Company
;
return
Company
;
};
};
src/person.js
View file @
459918e8
...
@@ -3,15 +3,14 @@
...
@@ -3,15 +3,14 @@
var
assert
=
require
(
'assert'
);
var
assert
=
require
(
'assert'
);
var
_
=
require
(
'lodash'
);
var
_
=
require
(
'lodash'
);
var
Promise
=
require
(
'bluebird'
);
var
Promise
=
require
(
'bluebird'
);
var
utils
=
require
(
'./utils'
)
module
.
exports
=
function
(
client
)
{
module
.
exports
=
function
(
client
)
{
function
Person
(
data
)
{
function
Person
(
data
)
{
_
.
extend
(
this
,
data
);
_
.
extend
(
this
,
data
);
}
}
Person
.
prototype
.
pending
=
function
()
{
Person
.
prototype
.
pending
=
utils
.
pending
;
return
!
this
.
id
;
};
Person
.
find
=
Promise
.
method
(
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'
);
...
@@ -21,12 +20,14 @@ module.exports = function (client) {
...
@@ -21,12 +20,14 @@ module.exports = function (client) {
query
:
_
.
pick
(
options
,
'subscribe'
,
'company'
)
query
:
_
.
pick
(
options
,
'subscribe'
,
'company'
)
},
options
))
},
options
))
.
bind
(
this
)
.
bind
(
this
)
.
then
(
function
(
data
)
{
.
then
(
utils
.
cast
)
return
new
this
(
data
);
.
catch
(
utils
.
isUnknownRecord
,
function
(
err
)
{
throw
new
this
.
NotFoundError
(
'Person not found'
);
});
});
});
});
Person
.
prototype
.
client
=
Person
.
client
=
client
;
Person
.
prototype
.
client
=
Person
.
client
=
client
;
Person
.
NotFoundError
=
utils
.
NotFoundError
;
return
Person
;
return
Person
;
};
};
src/utils.js
0 → 100644
View file @
459918e8
'use strict'
;
var
createError
=
require
(
'create-error'
);
exports
.
cast
=
function
(
data
)
{
return
new
this
(
data
);
};
exports
.
pending
=
function
()
{
return
!
this
.
id
;
};
exports
.
NotFoundError
=
createError
(
'NotFoundError'
);
exports
.
isUnknownRecord
=
function
(
err
)
{
return
err
.
type
===
'unknown_record'
;
};
test/company.js
View file @
459918e8
...
@@ -52,6 +52,18 @@ describe('Company', function () {
...
@@ -52,6 +52,18 @@ describe('Company', function () {
});
});
});
});
it
(
'can handle unknown records'
,
function
()
{
mock
.
get
(
'/v1/companies/domain/nonexistent.co'
)
.
reply
(
404
,
{
error
:
{
type
:
'unknown_record'
}
});
return
expect
(
Company
.
find
({
domain
:
'nonexistent.co'
}))
.
to
.
be
.
rejectedWith
(
Company
.
NotFoundError
);
});
});
});
});
});
test/person.js
View file @
459918e8
'use strict'
;
'use strict'
;
var
expect
=
require
(
'chai'
).
expect
;
var
expect
=
require
(
'chai'
).
use
(
require
(
'chai-as-promised'
)).
expect
;
var
nock
=
require
(
'nock'
);
var
nock
=
require
(
'nock'
);
var
Person
=
require
(
'../'
)(
'k'
).
Person
;
var
Person
=
require
(
'../'
)(
'k'
).
Person
;
...
@@ -66,6 +66,18 @@ describe('Person', function () {
...
@@ -66,6 +66,18 @@ describe('Person', function () {
});
});
});
});
it
(
'can handle unknown records'
,
function
()
{
mock
.
get
(
'/v1/people/email/bademail@unknown.com'
)
.
reply
(
404
,
{
error
:
{
type
:
'unknown_record'
}
});
return
expect
(
Person
.
find
({
email
:
'bademail@unknown.com'
}))
.
to
.
be
.
rejectedWith
(
Person
.
NotFoundError
);
});
});
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment