fix(sidebar): explicitly detect 202 and cache null people

This commit is contained in:
Evan Morikawa 2016-03-10 18:16:32 -05:00
parent e8e4761e45
commit 5dbef230a3
3 changed files with 32 additions and 15 deletions

View file

@ -13,22 +13,35 @@ module.exports = class ClearbitDataSource
user: tok
pass: ""
path: "/proxy/clearbit/#{@clearbitAPI()}/find?email=#{email}",
success: (body) =>
resolve(@parseResponse(body))
success: (body, response) =>
resolve(@parseResponse(body, response, email))
error: reject
# The clearbit -> Nylas adapater
parseResponse: (resp={}) ->
person = resp.person
return null unless person
cacheDate: Date.now()
email: person.email # Used as checksum
bio: person.bio ? person.twitter?.bio ? person.aboutme?.bio,
location: person.location ? person.geo?.city
currentTitle: person.employment?.title,
currentEmployer: person.employment?.name,
profilePhotoUrl: person.avatar,
socialProfiles: @_socialProfiles(person)
parseResponse: (body={}, response, requestedEmail) ->
# This means it's in the process of fetching. Return null so we don't
# cache and try again.
if response.statusCode isnt 200
return null
person = body.person
# This means there was no data about the person available. Return a
# valid, but empty object for us to cache. This can happen when we
# have company data, but no personal data.
if not person
return {email: requestedEmail}
return {
cacheDate: Date.now()
email: person.email # Used as checksum
bio: person.bio ? person.twitter?.bio ? person.aboutme?.bio,
location: person.location ? person.geo?.city
currentTitle: person.employment?.title,
currentEmployer: person.employment?.name,
profilePhotoUrl: person.avatar,
socialProfiles: @_socialProfiles(person)
}
_socialProfiles: (person={}) ->
profiles = {}

View file

@ -24,7 +24,11 @@ class ParticipantProfileStore extends NylasStore {
}
if (this.inCache(contact)) {
return this.getCache(contact)
const data = this.getCache(contact);
if (data.cacheDate) {
return data
}
return {}
}
this.dataSource.find({email: contact.email}).then((data) => {

View file

@ -53,7 +53,7 @@ class EdgehillAPI
if error? or response.statusCode > 299
options.error(new APIError({error:error, response:response, body:body, requestOptions: options}))
else
options.success(body) if options.success
options.success(body, response) if options.success
_defaultErrorCallback: (apiError) ->
console.error(apiError)