diff --git a/frontend/flashcards.html b/frontend/flashcards.html
index 8377a4e..9078d8c 100644
--- a/frontend/flashcards.html
+++ b/frontend/flashcards.html
@@ -802,14 +802,24 @@ async function persistCardOrder() {
}
async function addCard() {
- if (!_curDeck) return;
+ if (!_curDeck) { LS.toast('Сначала откройте колоду', 'error'); return; }
const front = document.getElementById('new-card-front').value.trim();
const back = document.getElementById('new-card-back').value.trim();
- if (!front && !back && !_newImg.front && !_newImg.back) return;
- const card = await LS.api(`/api/flashcards/decks/${_curDeck.id}/cards`, {
- method: 'POST',
- body: JSON.stringify({ front, back, front_image: _newImg.front, back_image: _newImg.back })
- }).catch(()=>null);
+ if (!front && !back && !_newImg.front && !_newImg.back) {
+ LS.toast('Введите вопрос или ответ карточки');
+ document.getElementById('new-card-front').focus();
+ return;
+ }
+ let card;
+ try {
+ card = await LS.api(`/api/flashcards/decks/${_curDeck.id}/cards`, {
+ method: 'POST',
+ body: JSON.stringify({ front, back, front_image: _newImg.front, back_image: _newImg.back })
+ });
+ } catch (e) {
+ LS.toast('Не удалось добавить карточку: ' + (e && e.message || 'ошибка'), 'error');
+ return;
+ }
if (!card) return;
_cards.push(card);
document.getElementById('new-card-front').value = '';