Open alexlatchford opened 7 years ago
Oops - will fix this.
This has not been resolved -- due to this issue we have to apply some pretty ugly workaround code such as:
/**
* It is necessary to perform a conditional type or name check to determine
* if a clearbit email was invalid or not found.
* @see https://github.com/clearbit/clearbit-node/issues/24
*/
const clearbitNoResultErrorTypes = ['email_invalid'] as const
const clearbitNoResultErrorNames = ['EnrichmentNotFoundError'] as const
interface IClearbitNoResultError {
type?: typeof clearbitNoResultErrorTypes
name: typeof clearbitNoResultErrorNames | 'ClearbitError'
}
const isClearbitNoResultError = (err: any): err is IClearbitNoResultError =>
clearbitNoResultErrorTypes.includes(err.type) || clearbitNoResultErrorNames.includes(err.name)
try {
const { company, person } = await clearbitClient.Enrichment.find({ email, stream: true })
if (company || person) {
console.log('enriched email %s with clearbit to company %o and person %o', email, company, person)
}
} catch (e) {
if (!isClearbitNoResultError(e)) {
throw e
}
else {
console.log('no results found for email: ' + email)
}
}
Just parsing through the various errors we get back from a bunch of calls and looks like "PersonNotFound" returns with:
All the other errors seem like they have an
error.type
property I can check and/or astatusCode
attribute. Any chance we can add this in to make this one consistent, I'll match against the message for now :)Thanks, Alex