mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-30 08:03:08 +02:00
enhance(client): improve api error handling
This commit is contained in:
parent
ef860a8f84
commit
f5bfc6f0c1
2 changed files with 28 additions and 2 deletions
|
@ -952,6 +952,9 @@ thisPostMayBeAnnoyingHome: "ホームに投稿"
|
||||||
thisPostMayBeAnnoyingCancel: "やめる"
|
thisPostMayBeAnnoyingCancel: "やめる"
|
||||||
thisPostMayBeAnnoyingIgnore: "このまま投稿"
|
thisPostMayBeAnnoyingIgnore: "このまま投稿"
|
||||||
collapseRenotes: "見たことのあるRenoteを省略して表示"
|
collapseRenotes: "見たことのあるRenoteを省略して表示"
|
||||||
|
internalServerError: "サーバー内部エラー"
|
||||||
|
internalServerErrorDescription: "サーバー内部で予期しないエラーが発生しました。"
|
||||||
|
copyErrorInfo: "エラー情報をコピー"
|
||||||
|
|
||||||
_achievements:
|
_achievements:
|
||||||
earnedAt: "獲得日時"
|
earnedAt: "獲得日時"
|
||||||
|
|
|
@ -17,6 +17,7 @@ import MkEmojiPickerWindow from '@/components/MkEmojiPickerWindow.vue';
|
||||||
import MkPopupMenu from '@/components/MkPopupMenu.vue';
|
import MkPopupMenu from '@/components/MkPopupMenu.vue';
|
||||||
import MkContextMenu from '@/components/MkContextMenu.vue';
|
import MkContextMenu from '@/components/MkContextMenu.vue';
|
||||||
import { MenuItem } from '@/types/menu';
|
import { MenuItem } from '@/types/menu';
|
||||||
|
import copyToClipboard from './scripts/copy-to-clipboard';
|
||||||
|
|
||||||
export const openingWindowsCount = ref(0);
|
export const openingWindowsCount = ref(0);
|
||||||
|
|
||||||
|
@ -26,10 +27,32 @@ export const apiWithDialog = ((
|
||||||
token?: string | null | undefined,
|
token?: string | null | undefined,
|
||||||
) => {
|
) => {
|
||||||
const promise = api(endpoint, data, token);
|
const promise = api(endpoint, data, token);
|
||||||
promiseDialog(promise, null, (err) => {
|
promiseDialog(promise, null, async (err) => {
|
||||||
let title = null;
|
let title = null;
|
||||||
let text = err.message + '\n' + (err as any).id;
|
let text = err.message + '\n' + (err as any).id;
|
||||||
if (err.code === 'RATE_LIMIT_EXCEEDED') {
|
if (err.code === 'INTERNAL_ERROR') {
|
||||||
|
title = i18n.ts.internalServerError;
|
||||||
|
text = i18n.ts.internalServerErrorDescription;
|
||||||
|
const date = new Date().toISOString();
|
||||||
|
const { result } = await actions({
|
||||||
|
type: 'error',
|
||||||
|
title,
|
||||||
|
text,
|
||||||
|
actions: [{
|
||||||
|
value: 'ok',
|
||||||
|
text: i18n.ts.gotIt,
|
||||||
|
primary: true,
|
||||||
|
}, {
|
||||||
|
value: 'copy',
|
||||||
|
text: i18n.ts.copyErrorInfo,
|
||||||
|
}],
|
||||||
|
});
|
||||||
|
if (result === 'copy') {
|
||||||
|
copyToClipboard(`Endpoint: ${endpoint}\nInfo: ${JSON.stringify(err.info)}\nDate: ${date}`);
|
||||||
|
success();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
} else if (err.code === 'RATE_LIMIT_EXCEEDED') {
|
||||||
title = i18n.ts.cannotPerformTemporary;
|
title = i18n.ts.cannotPerformTemporary;
|
||||||
text = i18n.ts.cannotPerformTemporaryDescription;
|
text = i18n.ts.cannotPerformTemporaryDescription;
|
||||||
} else if (err.code.startsWith('TOO_MANY')) {
|
} else if (err.code.startsWith('TOO_MANY')) {
|
||||||
|
|
Loading…
Reference in a new issue