Skip to content

Commit

Permalink
better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
kakkokari-gtyih committed Oct 12, 2024
1 parent 02e85ca commit 5670b29
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ watch(name, () => {
// 空文字列をnullにしたいので??は使うな
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
name: name.value || null,
}, undefined, {
'SCREEN_NAME_CONTAINS_PROHIBITED_WORDS': {
title: i18n.ts.screenNameContainsProhibitedWords,
text: i18n.ts.screenNameContainsProhibitedWordsDescription,
},
});
});
Expand Down
9 changes: 5 additions & 4 deletions packages/frontend/src/os.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const apiWithDialog = (<E extends keyof Misskey.Endpoints = keyof Misskey
endpoint: E,
data: P = {} as any,
token?: string | null | undefined,
customErrors?: Record<string, { title?: string; text: string; }>,
) => {
const promise = misskeyApi(endpoint, data, token);
promiseDialog(promise, null, async (err) => {
Expand Down Expand Up @@ -77,9 +78,9 @@ export const apiWithDialog = (<E extends keyof Misskey.Endpoints = keyof Misskey
} else if (err.message.startsWith('Unexpected token')) {
title = i18n.ts.gotInvalidResponseError;
text = i18n.ts.gotInvalidResponseErrorDescription;
} else if (err.code === 'SCREEN_NAME_CONTAINS_PROHIBITED_WORDS') {
title = i18n.ts.screenNameContainsProhibitedWords;
text = i18n.ts.screenNameContainsProhibitedWordsDescription;
} else if (customErrors && customErrors[err.code] != null) {
title = customErrors[err.code].title;
text = customErrors[err.code].text;
}
alert({
type: 'error',
Expand All @@ -89,7 +90,7 @@ export const apiWithDialog = (<E extends keyof Misskey.Endpoints = keyof Misskey
});

return promise;
}) as typeof misskeyApi;
});

export function promiseDialog<T extends Promise<any>>(
promise: T,
Expand Down
5 changes: 5 additions & 0 deletions packages/frontend/src/pages/settings/profile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ function save() {
lang: profile.lang || null,
isBot: !!profile.isBot,
isCat: !!profile.isCat,
}, undefined, {
'SCREEN_NAME_CONTAINS_PROHIBITED_WORDS': {
title: i18n.ts.screenNameContainsProhibitedWords,
text: i18n.ts.screenNameContainsProhibitedWordsDescription,
},
});
globalEvents.emit('requestClearPageCache');
claimAchievement('profileFilled');
Expand Down

0 comments on commit 5670b29

Please sign in to comment.