Skip to content

Commit

Permalink
Catch errors in /announcement
Browse files Browse the repository at this point in the history
  • Loading branch information
maxwofford committed Sep 28, 2019
1 parent 42a1919 commit 4201f4c
Showing 1 changed file with 29 additions and 22 deletions.
51 changes: 29 additions & 22 deletions src/interactions/announcement.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,37 @@ const interactionAnnouncement = (bot, message) => {
)
}

getInfoForUser(user).then(({ slackUser, userRecord }) => {
if (!slackUser.is_owner) {
throw new Error('This command can only be run by Slack Owner accounts')
}
getInfoForUser(user)
.then(({ slackUser, userRecord }) => {
if (!slackUser.is_owner) {
throw new Error('This command can only be run by Slack Owner accounts')
}

const announcementData = userRecord.fields.announcement
if (verb == 'record') {
const content = text
userRecord.patch({ announcement: { content } }).catch(err => {
throw err
const announcementData = userRecord.fields.announcement
if (verb == 'record') {
const content = text
userRecord.patch({ announcement: { content } }).catch(err => {
throw err
})
} else if (verb == 'address') {
const target = text
userRecord.patch({ announcement: { target } }).catch(err => {
throw err
})
} else if (verb == 'status') {
bot.replyPrivateDelayed(message, transcript('announcement.status'), {
announcementData,
})
} else if (verb == 'send') {
console.log('got Send command')
}
})
.catch(err => {
bot.replyPrivateDelayed(message, transcript('errors.general'), {
err,
})
} else if (verb == 'address') {
const target = text
userRecord.patch({ announcement: { target } }).catch(err => {
throw err
})
} else if (verb == 'status') {
bot.replyPrivateDelayed(message, transcript('announcement.status'), {
announcementData,
})
} else if (verb == 'send') {
console.log('got Send command')
}
})
console.error(err)
})
}

export default interactionAnnouncement

0 comments on commit 4201f4c

Please sign in to comment.