diff --git a/internal_packages/participant-profile/lib/clearbit-data-source.coffee b/internal_packages/participant-profile/lib/clearbit-data-source.coffee index 2a7eb775d..f9fcef194 100644 --- a/internal_packages/participant-profile/lib/clearbit-data-source.coffee +++ b/internal_packages/participant-profile/lib/clearbit-data-source.coffee @@ -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 = {} diff --git a/internal_packages/participant-profile/lib/participant-profile-store.js b/internal_packages/participant-profile/lib/participant-profile-store.js index 1c62437c0..79cff16ba 100644 --- a/internal_packages/participant-profile/lib/participant-profile-store.js +++ b/internal_packages/participant-profile/lib/participant-profile-store.js @@ -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) => { diff --git a/src/flux/edgehill-api.coffee b/src/flux/edgehill-api.coffee index 6645d8b94..9804d30a1 100644 --- a/src/flux/edgehill-api.coffee +++ b/src/flux/edgehill-api.coffee @@ -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)