fix: enhance error handling for tag saving process and improve CSRF token retrieval
This commit is contained in:
@@ -1277,7 +1277,8 @@
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-TOKEN': document.querySelector('meta[name=csrf-token]').content
|
||||
'Accept': 'application/json',
|
||||
'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]')?.getAttribute('content') || ''
|
||||
},
|
||||
body: JSON.stringify({
|
||||
tag1: this.tag1.trim(),
|
||||
@@ -1288,7 +1289,14 @@
|
||||
tag3color: this.tag3color
|
||||
})
|
||||
})
|
||||
.then(r => r.json())
|
||||
.then(r => {
|
||||
if (!r.ok) {
|
||||
return r.text().then(text => {
|
||||
throw new Error(`HTTP ${r.status}: ${text.substring(0, 100)}`);
|
||||
});
|
||||
}
|
||||
return r.json();
|
||||
})
|
||||
.then(data => {
|
||||
this.saving = false;
|
||||
if (data.success) {
|
||||
@@ -1302,8 +1310,9 @@
|
||||
})
|
||||
.catch(err => {
|
||||
this.saving = false;
|
||||
this.message = 'Error saving tags';
|
||||
this.message = 'Error: ' + err.message;
|
||||
this.messageType = 'error';
|
||||
console.error('Tag save error:', err);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user