Skip to content

Commit

Permalink
fix(SubmitConfirmModal): handle errors when fetching community catego…
Browse files Browse the repository at this point in the history
…ries and publishing posts

feat(SubmitConfirmModal): add error handling for getMyCommunities API call and post submission
  • Loading branch information
anpigon committed Jun 27, 2024
1 parent 9deafee commit 95b038c
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions src/ui/submit_confirm_modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,22 @@ export class SubmitConfirmModal extends Modal {

// 커뮤니티 카테고리를 가져온다.
async getCommunityCategories(category?: string) {
const myCommunities = await this.plugin.client?.getMyCommunities();
const categoryOptions = myCommunities?.reduce<Record<string, string>>(
(a, b) => ({ ...a, [b.name]: b.title }),
{},
);
return {
'': 'My Blog',
...(category && { [category]: 'My Blog' }),
...categoryOptions,
};
try {
const myCommunities = await this.plugin.client?.getMyCommunities();
const categoryOptions = myCommunities?.reduce<Record<string, string>>(
(a, b) => ({ ...a, [b.name]: b.title }),
{},
);
return {
'': 'My Blog',
...(category && { [category]: 'My Blog' }),
...categoryOptions,
};
} catch (error) {
console.error(error);
new Notice('Error fetching community categories. Please check your settings.');
return { '': 'My Blog' };
}
}

validateRequiredFields() {
Expand All @@ -55,8 +61,13 @@ export class SubmitConfirmModal extends Modal {

async handleSubmit() {
if (this.validateRequiredFields()) {
this.callback(this.postData, this.postOptions);
this.close();
try {
this.callback(this.postData, this.postOptions);
this.close();
} catch (error) {
console.error(error);
new Notice('Error publishing post. Please check your settings.');
}
}
}

Expand Down

0 comments on commit 95b038c

Please sign in to comment.