- Affected version
- 2.2.13
If a user submits twice rapidly; instead of a useful message for users, an internal server error is instead generated.
In this case, catching the
Code:
[LIST]
[*]XF\Db\DuplicateKeyException: MySQL query error [1062]: Duplicate entry 'epic beatdown-529994' for key 'label_user_id'
[*]src/XF/Db/AbstractStatement.php:230
[*]Generated by: xxx
[*]Sep 21, 2023 at 5:30 AM
[/LIST]
[HEADING=2]Stack trace[/HEADING]
INSERT INTO `xf_bookmark_label` (`label`, `user_id`, `label_url`, `label_id`, `use_count`, `last_use_date`) VALUES (?, ?, ?, ?, ?, ?)
------------
#0 src/XF/Db/Mysqli/Statement.php(198): XF\Db\AbstractStatement->getException('MySQL query err...', 1062, '23000')
#1 src/XF/Db/Mysqli/Statement.php(79): XF\Db\Mysqli\Statement->getException('MySQL query err...', 1062, '23000')
#2 src/XF/Db/AbstractAdapter.php(96): XF\Db\Mysqli\Statement->execute()
#3 src/XF/Db/AbstractAdapter.php(220): XF\Db\AbstractAdapter->query('INSERT INTO `x...', Array)
#4 src/XF/Mvc/Entity/Entity.php(1521): XF\Db\AbstractAdapter->insert('xf_bookmark_lab...', Array, false)
#5 src/XF/Mvc/Entity/Entity.php(1253): XF\Mvc\Entity\Entity->_saveToSource()
#6 src/XF/Repository/Bookmark.php(322): XF\Mvc\Entity\Entity->save()
#7 src/XF/Service/Bookmark/LabelChanger.php(85): XF\Repository\Bookmark->createLabelForUser('epic beatdown', Object(XF\Entity\User))
#8 src/XF/Service/Bookmark/Editor.php(77): XF\Service\Bookmark\LabelChanger->save()
#9 src/XF/Service/ValidateAndSavableTrait.php(42): XF\Service\Bookmark\Editor->_save()
#10 src/XF/ControllerPlugin/Bookmark.php(188): XF\Service\Bookmark\Editor->save()
#11 src/XF/ControllerPlugin/Bookmark.php(23): XF\ControllerPlugin\Bookmark->actionSaveBookmark(Object(XF\Entity\Post), '/posts/88491285...')
#12 src/XF/Pub/Controller/Post.php(371): XF\ControllerPlugin\Bookmark->actionBookmark(Object(XF\Entity\Post), '/posts/88491285...')
#13 src/XF/Mvc/Dispatcher.php(352): XF\Pub\Controller\Post->actionBookmark(Object(XF\Mvc\ParameterBag))
#14 src/XF/Mvc/Dispatcher.php(259): XF\Mvc\Dispatcher->dispatchClass('XF:Post', 'Bookmark', Object(XF\Mvc\RouteMatch), Object(XF\Pub\Controller\Post), NULL)
#15 src/XF/Mvc/Dispatcher.php(115): XF\Mvc\Dispatcher->dispatchFromMatch(Object(XF\Mvc\RouteMatch), Object(XF\Pub\Controller\Post), NULL)
#16 src/XF/Mvc/Dispatcher.php(57): XF\Mvc\Dispatcher->dispatchLoop(Object(XF\Mvc\RouteMatch))
#17 src/XF/App.php(2487): XF\Mvc\Dispatcher->run()
#18 src/XF.php(524): XF\App->run()
#19 index.php(20): XF::runApp('XF\\Pub\\App')
#20 {main}
In this case, catching the
DuplicateKeyException
and presenting a useful error message makes sense.