fix: align note edit errors with note create errors

This commit is contained in:
Marie 2024-02-23 17:01:35 +01:00
parent 15d2319011
commit d1b787192a
No known key found for this signature in database
GPG key ID: 56569BBE47D2C828
2 changed files with 42 additions and 27 deletions

View file

@ -51,6 +51,7 @@ import { CacheService } from '@/core/CacheService.js';
import { isReply } from '@/misc/is-reply.js'; import { isReply } from '@/misc/is-reply.js';
import { trackPromise } from '@/misc/promise-tracker.js'; import { trackPromise } from '@/misc/promise-tracker.js';
import { isUserRelated } from '@/misc/is-user-related.js'; import { isUserRelated } from '@/misc/is-user-related.js';
import { IdentifiableError } from '@/misc/identifiable-error.js';
type NotificationType = 'reply' | 'renote' | 'quote' | 'mention' | 'edited'; type NotificationType = 'reply' | 'renote' | 'quote' | 'mention' | 'edited';
@ -244,8 +245,7 @@ export class NoteEditService implements OnApplicationShutdown {
// we never want to change the replyId, so fetch the original "parent" // we never want to change the replyId, so fetch the original "parent"
if (oldnote.replyId) { if (oldnote.replyId) {
data.reply = await this.notesRepository.findOneBy({ id: oldnote.replyId }); data.reply = await this.notesRepository.findOneBy({ id: oldnote.replyId });
} } else {
else {
data.reply = undefined; data.reply = undefined;
} }
@ -284,7 +284,7 @@ export class NoteEditService implements OnApplicationShutdown {
} }
if (this.utilityService.isKeyWordIncluded(data.cw ?? data.text ?? '', meta.prohibitedWords)) { if (this.utilityService.isKeyWordIncluded(data.cw ?? data.text ?? '', meta.prohibitedWords)) {
throw new NoteEditService.ContainsProhibitedWordsError(); throw new IdentifiableError('689ee33f-f97c-479a-ac49-1b9f8140af99', 'Note contains prohibited words');
} }
const inSilencedInstance = this.utilityService.isSilencedHost((meta).silencedHosts, user.host); const inSilencedInstance = this.utilityService.isSilencedHost((meta).silencedHosts, user.host);

View file

@ -11,6 +11,7 @@ import { Endpoint } from '@/server/api/endpoint-base.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js'; import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { NoteEditService } from '@/core/NoteEditService.js'; import { NoteEditService } from '@/core/NoteEditService.js';
import { DI } from '@/di-symbols.js'; import { DI } from '@/di-symbols.js';
import { IdentifiableError } from '@/misc/identifiable-error.js';
import { ApiError } from '../../error.js'; import { ApiError } from '../../error.js';
export const meta = { export const meta = {
@ -141,6 +142,12 @@ export const meta = {
code: 'MAX_LENGTH', code: 'MAX_LENGTH',
id: '3ac74a84-8fd5-4bb0-870f-01804f82ce16', id: '3ac74a84-8fd5-4bb0-870f-01804f82ce16',
}, },
containsProhibitedWords: {
message: 'Cannot post because it contains prohibited words.',
code: 'CONTAINS_PROHIBITED_WORDS',
id: 'aa6e01d3-a85c-669d-758a-76aab43af334',
},
}, },
} as const; } as const;
@ -379,7 +386,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
throw new ApiError(meta.errors.noSuchChannel); throw new ApiError(meta.errors.noSuchChannel);
} }
} }
try {
// 投稿を作成 // 投稿を作成
const note = await this.noteEditService.edit(me, ps.editId!, { const note = await this.noteEditService.edit(me, ps.editId!, {
files: files, files: files,
@ -405,6 +412,14 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
return { return {
createdNote: await this.noteEntityService.pack(note, me), createdNote: await this.noteEntityService.pack(note, me),
}; };
} catch (e) {
// TODO: 他のErrorもここでキャッチしてエラーメッセージを当てるようにしたい
if (e instanceof IdentifiableError) {
if (e.id === '689ee33f-f97c-479a-ac49-1b9f8140af99') throw new ApiError(meta.errors.containsProhibitedWords);
}
throw e;
}
}); });
} }
} }