Skip to content

Commit

Permalink
fix(builtins): catch unique constraint violation
Browse files Browse the repository at this point in the history
  • Loading branch information
emirotin authored and epaminond committed Sep 27, 2018
1 parent c56ceb0 commit a89942c
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions packages/core/botpress-builtins/src/setup.js
Expand Up @@ -23,8 +23,15 @@ export default function(bp) {
return next()
}

const convoCount = await bp.users.getTag(stateId, USER_TAG_CONVO_COUNT)
await bp.users.tag(stateId, USER_TAG_CONVO_COUNT, parseInt(convoCount || 0) + 1)
// TODO: implement proper atomic increment
// and eliminate simultaneous INSERTs that violate
// unique constraint
try {
const convoCount = await bp.users.getTag(stateId, USER_TAG_CONVO_COUNT)
await bp.users.tag(stateId, USER_TAG_CONVO_COUNT, parseInt(convoCount || 0) + 1)
} catch (err) {
// console.error(err.message)
}

next()
})
Expand All @@ -41,8 +48,14 @@ export default function(bp) {
return next()
}

const position = await bp.dialogEngine.getCurrentPosition(stateId)
await bp.users.tag(stateId, USER_TAG_CONVO_LAST, position && position.flow)
// TODO: eliminate simultaneous INSERTs that violate
// unique constraint
try {
const position = await bp.dialogEngine.getCurrentPosition(stateId)
await bp.users.tag(stateId, USER_TAG_CONVO_LAST, position && position.flow)
} catch (err) {
// console.error(err.message)
}

//
// Cleans up Conversation Storage variables
Expand Down

0 comments on commit a89942c

Please sign in to comment.