Skip to content

Commit

Permalink
fix: cloud sync error wasn't show
Browse files Browse the repository at this point in the history
  • Loading branch information
Tsuk1ko committed Nov 2, 2024
1 parent 48ea333 commit da96a09
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
10 changes: 9 additions & 1 deletion src/utils/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,20 @@ export default {
mode: 'cors',
}).then(r => r.json()),
getJson: async id =>
fetch(`${JSON_STORAGE_BASE_URL}/${id}`, { mode: 'cors' }).then(r => r.json()),
fetch(`${JSON_STORAGE_BASE_URL}/${id}`, { mode: 'cors' }).then(r => {
if (r.status === 404) return null;
if (r.status !== 200) throw new Error(r.statusText);
return r.json();
}),
updateJson: async (id, obj) =>
fetch(`${JSON_STORAGE_BASE_URL}/${id}`, {
method: 'PUT',
body: JSON.stringify(obj),
headers: { 'Content-Type': 'application/json' },
mode: 'cors',
}).then(r => {
if (r.status === 404) return false;
if (r.status !== 200) throw new Error(r.statusText);
return true;
}),
};
30 changes: 16 additions & 14 deletions src/views/Material/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1320,28 +1320,30 @@ export default defineComponent({
this.dataSyncing = true;
if (this.syncCode) {
Ajax.updateJson(this.syncCode, data)
.then(() => {
this.dataSyncing = false;
if (!silence) this.$snackbar(this.$t('cultivate.snackbar.backupSucceeded'));
.then(success => {
if (success) {
if (!silence) this.$snackbar(this.$t('cultivate.snackbar.backupSucceeded'));
return;
}
this.$snackbar(this.$t('cultivate.snackbar.syncCodeInvalid'));
})
.catch(e => {
this.$snackbar(`${this.$t('cultivate.snackbar.backupFailed')} ${e}`);
})
.finally(() => {
this.dataSyncing = false;
this.$snackbar(
`${this.$t('cultivate.snackbar.backupFailed')} ${e.responseText || e.message || ''}`,
);
});
} else {
Ajax.createJson(data)
.then(({ id }) => {
this.dataSyncing = false;
this.syncCode = id;
this.$snackbar(this.$t('cultivate.snackbar.backupSucceeded'));
})
.catch(e => {
this.$snackbar(`${this.$t('cultivate.snackbar.backupFailed')} ${e}`);
})
.finally(() => {
this.dataSyncing = false;
this.$snackbar(
`${this.$t('cultivate.snackbar.backupFailed')} ${e.responseText || e.message || ''}`,
);
});
}
if (!silence) {
Expand All @@ -1357,20 +1359,20 @@ export default defineComponent({
Ajax.getJson(this.syncCode)
.then(data => {
if (!data) {
this.dataSyncing = false;
this.$snackbar(this.$t('cultivate.snackbar.restoreFailed'));
this.$snackbar(this.$t('cultivate.snackbar.syncCodeInvalid'));
return;
}
this.ignoreNextInputsChange = true;
this.dataForSave = data;
this.$snackbar(this.$t('cultivate.snackbar.restoreSucceeded'));
this.dataSyncing = false;
})
.catch(e => {
this.dataSyncing = false;
this.$snackbar(
`${this.$t('cultivate.snackbar.restoreFailed')} ${e.responseText || e.message || ''}`,
);
})
.finally(() => {
this.dataSyncing = false;
});
this.$gtag.event('material_cloud_restore', {
event_category: 'material',
Expand Down

0 comments on commit da96a09

Please sign in to comment.