diff --git a/packages/backend/src/remote/activitypub/models/note.ts b/packages/backend/src/remote/activitypub/models/note.ts index be4f44f69..8436f7c3d 100644 --- a/packages/backend/src/remote/activitypub/models/note.ts +++ b/packages/backend/src/remote/activitypub/models/note.ts @@ -30,20 +30,20 @@ import { extractApMentions } from './mention.js'; import { normalizeForSearch } from '@/misc/normalize-for-search.js'; import { sideEffects } from '@/services/note/side-effects.js'; -export function validateNote(object: IObject): Error | null { +function validateNote(object: IObject) { if (object == null) { - return new Error('invalid Note: object is null'); + throw new Error('invalid Note: object is null'); } if (!isPost(object)) { - return new Error(`invalid Note: invalid object type ${getApType(object)}`); + throw new Error(`invalid Note: invalid object type ${getApType(object)}`); } const id = getApId(object); if (id == null) { // Only transient objects or anonymous objects may not have an id or an id that is explicitly null. // We consider all Notes as not transient and not anonymous so require ids for them. - return new Error(`invalid Note: id required but not present`); + throw new Error(`invalid Note: id required but not present`); } // Check that the server is authorized to act on behalf of this author. @@ -52,13 +52,11 @@ export function validateNote(object: IObject): Error | null { ? extractPunyHost(getOneApId(object.attributedTo)) : null; if (attributedToHost !== expectHost) { - return new Error(`invalid Note: attributedTo has different host. expected: ${expectHost}, actual: ${attributedToHost}`); + throw new Error(`invalid Note: attributedTo has different host. expected: ${expectHost}, actual: ${attributedToHost}`); } if (attributedToHost === config.hostname) { - return new Error('invalid Note: by local author'); + throw new Error('invalid Note: by local author'); } - - return null; } /** @@ -127,11 +125,7 @@ export async function fetchNote(object: string | IObject): Promise export async function createNote(value: string | IObject, resolver: Resolver, silent = false): Promise { const object: IObject = await resolver.resolve(value); - const err = validateNote(object); - if (err) { - apLogger.error(`${err.message}`); - throw new Error('invalid note'); - } + validateNote(object); const note: IPost = object; @@ -339,11 +333,7 @@ export async function resolveNote(value: string | IObject, resolver: Resolver): * If the target Note is not registered, it will be ignored. */ export async function updateNote(value: IPost, actor: User, resolver: Resolver): Promise { - const err = validateNote(value); - if (err) { - apLogger.error(`${err.message}`); - throw new Error('invalid updated note'); - } + validateNote(value); const uri = getApId(value); const exists = await Notes.findOneBy({ uri });