Skip to content

Commit 5670b29

Browse files
better error handling
1 parent 02e85ca commit 5670b29

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

packages/frontend/src/components/MkUserSetupDialog.Profile.vue

+5
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ watch(name, () => {
5151
// 空文字列をnullにしたいので??は使うな
5252
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
5353
name: name.value || null,
54+
}, undefined, {
55+
'SCREEN_NAME_CONTAINS_PROHIBITED_WORDS': {
56+
title: i18n.ts.screenNameContainsProhibitedWords,
57+
text: i18n.ts.screenNameContainsProhibitedWordsDescription,
58+
},
5459
});
5560
});
5661

packages/frontend/src/os.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export const apiWithDialog = (<E extends keyof Misskey.Endpoints = keyof Misskey
3535
endpoint: E,
3636
data: P = {} as any,
3737
token?: string | null | undefined,
38+
customErrors?: Record<string, { title?: string; text: string; }>,
3839
) => {
3940
const promise = misskeyApi(endpoint, data, token);
4041
promiseDialog(promise, null, async (err) => {
@@ -77,9 +78,9 @@ export const apiWithDialog = (<E extends keyof Misskey.Endpoints = keyof Misskey
7778
} else if (err.message.startsWith('Unexpected token')) {
7879
title = i18n.ts.gotInvalidResponseError;
7980
text = i18n.ts.gotInvalidResponseErrorDescription;
80-
} else if (err.code === 'SCREEN_NAME_CONTAINS_PROHIBITED_WORDS') {
81-
title = i18n.ts.screenNameContainsProhibitedWords;
82-
text = i18n.ts.screenNameContainsProhibitedWordsDescription;
81+
} else if (customErrors && customErrors[err.code] != null) {
82+
title = customErrors[err.code].title;
83+
text = customErrors[err.code].text;
8384
}
8485
alert({
8586
type: 'error',
@@ -89,7 +90,7 @@ export const apiWithDialog = (<E extends keyof Misskey.Endpoints = keyof Misskey
8990
});
9091

9192
return promise;
92-
}) as typeof misskeyApi;
93+
});
9394

9495
export function promiseDialog<T extends Promise<any>>(
9596
promise: T,

packages/frontend/src/pages/settings/profile.vue

+5
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,11 @@ function save() {
206206
lang: profile.lang || null,
207207
isBot: !!profile.isBot,
208208
isCat: !!profile.isCat,
209+
}, undefined, {
210+
'SCREEN_NAME_CONTAINS_PROHIBITED_WORDS': {
211+
title: i18n.ts.screenNameContainsProhibitedWords,
212+
text: i18n.ts.screenNameContainsProhibitedWordsDescription,
213+
},
209214
});
210215
globalEvents.emit('requestClearPageCache');
211216
claimAchievement('profileFilled');

0 commit comments

Comments
 (0)