Skip to content

Commit

Permalink
fix: mautic search exception
Browse files Browse the repository at this point in the history
  • Loading branch information
sirpy committed Sep 21, 2020
1 parent df75d4e commit fe44a1e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/server/mautic/mauticAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ export const Mautic = new (class {

async searchContact(email) {
const result = await this.baseQuery(`/contacts?search=${email}`, this.baseHeaders, null, 'get')
const ids = Object.keys(get(result, 'contacts', {}))
if (ids.length > 0) {
const ids = Object.keys(get(result || {}, 'contacts', {}))
if (ids.length > 1) {
this.log.warn('searchContact founds multiple ids:', ids)
}
return ids.sort()
Expand All @@ -123,7 +123,10 @@ export const Mautic = new (class {
email = get(contact, 'contact.fields.all.email')
}
if (!email) return false
const ids = await this.searchContact(email)
const ids = await this.searchContact(email).catch(e => {
this.log.warn('deleteDuplicate search failed:', email, e.message, e)
return []
})
if (ids.length > 1) {
this.log.warn('deleteDuplicate found duplicate user:', ids)
const toDelete = ids.filter(_ => _ !== mauticId).pop()
Expand Down

0 comments on commit fe44a1e

Please sign in to comment.