fix: Enhance error handling in file saving process (#11152)

* fix: Enhance error handling in file saving process

* f

* f
This commit is contained in:
KOMATA 2025-12-02 17:19:22 +08:00 committed by GitHub
parent 158180a052
commit 63b62f4074
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -393,7 +393,7 @@
<script lang="ts" setup>
import { createFile, getFileContent, getFilesTree, saveFileContent } from '@/api/modules/files';
import i18n from '@/lang';
import { MsgSuccess, MsgWarning } from '@/utils/message';
import { MsgError, MsgSuccess, MsgWarning } from '@/utils/message';
import * as monaco from 'monaco-editor';
import { computed, nextTick, onBeforeUnmount, onMounted, reactive, ref } from 'vue';
import { Languages } from '@/global/mimetype';
@ -867,19 +867,22 @@ const quickSave = () => {
saveContent();
};
const saveContent = () => {
const saveContent = async () => {
if (isEdit.value) {
loading.value = true;
saveFileContent(form.value)
.then(() => {
loading.value = false;
try {
const res = await saveFileContent(form.value);
if (res) {
isEdit.value = false;
oldFileContent.value = form.value.content;
MsgSuccess(i18n.global.t('commons.msg.updateSuccess'));
})
.catch(() => {
loading.value = false;
});
} else {
MsgError(i18n.global.t('commons.status.failed'));
isEdit.value = false;
}
} finally {
loading.value = false;
}
} else {
MsgWarning(i18n.global.t('file.noEdit'));
}