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

View file

@ -24,7 +24,11 @@ class ParticipantProfileStore extends NylasStore {
} }
if (this.inCache(contact)) { 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) => { this.dataSource.find({email: contact.email}).then((data) => {

View file

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