merge: Show popup when chat API returns an error (!1189)

View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/1189

Approved-by: dakkar <dakkar@thenautilus.net>
Approved-by: Marie <github@yuugi.dev>
This commit is contained in:
Marie 2025-07-27 14:17:26 +00:00
commit 4afd2cc14f
4 changed files with 51 additions and 7 deletions

View file

@ -0,0 +1,16 @@
/*
* SPDX-FileCopyrightText: hazelnoot and other Sharkey contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/
export class ChangeChatMessageTextType1753574755478 {
name = 'ChangeChatMessageTextType1753574755478'
async up(queryRunner) {
await queryRunner.query(`ALTER TABLE "chat_message" ALTER COLUMN "text" TYPE text`);
}
async down(queryRunner) {
await queryRunner.query(`ALTER TABLE "chat_message" ALTER COLUMN "text" TYPE varchar(4096)`);
}
}

View file

@ -50,8 +50,8 @@ export class MiChatMessage {
@JoinColumn()
public toRoom: MiChatRoom | null;
@Column('varchar', {
length: 4096, nullable: true,
@Column('text', {
nullable: true,
})
public text: string | null;

View file

@ -43,7 +43,7 @@ import * as os from '@/os.js';
import { i18n } from '@/i18n.js';
import { uploadFile } from '@/utility/upload.js';
import { miLocalStorage } from '@/local-storage.js';
import { misskeyApi } from '@/utility/misskey-api.js';
import { misskeyApi, printError } from '@/utility/misskey-api.js';
import { prefer } from '@/preferences.js';
import { Autocomplete } from '@/utility/autocomplete.js';
import { emojiPicker } from '@/utility/emoji-picker.js';
@ -194,8 +194,13 @@ function send() {
}).then(message => {
clear();
}).catch(err => {
console.error(err);
}).then(() => {
console.error('Error in chat:', err);
return os.alert({
type: 'error',
title: i18n.ts.error,
text: printError(err),
});
}).finally(() => {
sending.value = false;
});
} else if (props.room) {
@ -206,8 +211,13 @@ function send() {
}).then(message => {
clear();
}).catch(err => {
console.error(err);
}).then(() => {
console.error('Error in chat:', err);
return os.alert({
type: 'error',
title: i18n.ts.error,
text: printError(err),
});
}).finally(() => {
sending.value = false;
});
}

View file

@ -144,3 +144,21 @@ export function misskeyApiGet<
return promise;
}
export function printError(error: unknown): string {
if (error != null && typeof(error) === 'object') {
if ('info' in error && typeof (error.info) === 'object' && error.info) {
if ('e' in error.info && typeof (error.info.e) === 'object' && error.info.e) {
if ('message' in error.info.e && typeof (error.info.e.message) === 'string') return error.info.e.message;
if ('code' in error.info.e && typeof (error.info.e.code) === 'string') return error.info.e.code;
if ('id' in error.info.e && typeof (error.info.e.id) === 'string') return error.info.e.id;
}
}
if ('message' in error && typeof (error.message) === 'string') return error.message;
if ('code' in error && typeof (error.code) === 'string') return error.code;
if ('id' in error && typeof (error.id) === 'string') return error.id;
}
return String(error);
}