Skip to content

Commit

Permalink
Merge pull request #119 from hsingyin/master
Browse files Browse the repository at this point in the history
fix: 增加try catch
  • Loading branch information
hsingyin authored Nov 8, 2024
2 parents 0af1aed + b17dfb6 commit c56e434
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 39 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sub-store-front-end",
"version": "2.14.288",
"version": "2.14.289",
"private": true,
"scripts": {
"dev": "vite --host",
Expand Down
99 changes: 61 additions & 38 deletions src/store/subs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,20 +255,26 @@ export const useSubsStore = defineStore('subsStore', {
if ('data' in res[3].data) {
this.shares = res[3].data.data;
}
}).catch((err) => {
console.log('fetchSubsData err', err);
});
},
async updateOneData(type: string, name: string) {
let res;
if (type === 'subs') {
res = await subsApi.getOne('sub', name);
} else if (type === 'collections') {
res = await subsApi.getOne('collection', name);
} else if (type === 'files') {
res = await filesApi.getWholeFile(name);
}
if (res?.data?.status === 'success') {
const index = this[type].findIndex(item => item.name === name);
this[type][index] = res.data.data;
try {
let res;
if (type === 'subs') {
res = await subsApi.getOne('sub', name);
} else if (type === 'collections') {
res = await subsApi.getOne('collection', name);
} else if (type === 'files') {
res = await filesApi.getWholeFile(name);
}
if (res?.data?.status === 'success') {
const index = this[type].findIndex(item => item.name === name);
this[type][index] = res.data.data;
}
} catch (error) {
console.log('updateOneData error', error);
}
},
async fetchFlows(sub?: Sub[]) {
Expand Down Expand Up @@ -320,34 +326,44 @@ export const useSubsStore = defineStore('subsStore', {
// }
},
async deleteSub(type: SubsType, name: string) {
const { showNotify } = useAppNotifyStore();

const { data } = await subsApi.deleteSub(type, name);
if (data.status === 'success') {
await this.fetchSubsData();
showNotify({
type: 'danger',
title: t('subPage.deleteSub.succeedNotify'),
});
try {
const { showNotify } = useAppNotifyStore();

const { data } = await subsApi.deleteSub(type, name);
if (data.status === 'success') {
await this.fetchSubsData();
showNotify({
type: 'danger',
title: t('subPage.deleteSub.succeedNotify'),
});
}
} catch (error) {
console.log('deleteSub error', error);
}
},
async fetchFiles() {
Promise.all([filesApi.getWholeFiles()]).then(res => {
if ('data' in res[0].data) {
this.files = res[0].data.data;
}
}).catch((err) => {
console.log('fetchFiles err', err);
});
},
async deleteFile(name: string) {
const { showNotify } = useAppNotifyStore();

const { data } = await filesApi.deleteFile(name);
if (data.status === 'success') {
await this.fetchFiles();
showNotify({
type: 'danger',
title: t('filePage.deleteFile.succeedNotify'),
});
try {
const { showNotify } = useAppNotifyStore();

const { data } = await filesApi.deleteFile(name);
if (data.status === 'success') {
await this.fetchFiles();
showNotify({
type: 'danger',
title: t('filePage.deleteFile.succeedNotify'),
});
}
} catch (error) {
console.log('deleteFile error', error);
}
},
async fetchShareData() {
Expand All @@ -356,18 +372,24 @@ export const useSubsStore = defineStore('subsStore', {
console.log('res[0].data.data', res[0].data.data);
this.shares = res[0].data.data;
}
}).catch((err) => {
console.log('fetchShareData err', err);
});
},
async deleteShare(token: string, isShowNotify: boolean = true) {
const { showNotify } = useAppNotifyStore();

const { data } = await shareApi.deleteShare(token);
if (data.status === "success") {
await this.fetchShareData();
isShowNotify && showNotify({
type: "danger",
title: t("sharePage.deleteShare.succeedNotify"),
});
try {
const { showNotify } = useAppNotifyStore();

const { data } = await shareApi.deleteShare(token);
if (data.status === "success") {
await this.fetchShareData();
isShowNotify && showNotify({
type: "danger",
title: t("sharePage.deleteShare.succeedNotify"),
});
}
} catch (error) {
console.log('deleteShare error', error);
}
},
async updateShare(token: string, data: ShareToken) {
Expand All @@ -377,6 +399,7 @@ export const useSubsStore = defineStore('subsStore', {
await shareApi.createShare(data);
await this.fetchShareData();
} catch (error) {
console.log('updateShare error', error);
showNotify({
type: "danger",
title: t("sharePage.deleteShare.failNotify"),
Expand Down

0 comments on commit c56e434

Please sign in to comment.