From e3b3f8fac14fb4c4d150fb31c11ead1a193a36e0 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 14 Apr 2019 04:17:24 +0900 Subject: Better error handling --- src/remote/activitypub/kernel/accept/follow.ts | 2 +- src/remote/activitypub/kernel/block/index.ts | 2 +- src/remote/activitypub/kernel/follow.ts | 2 +- src/remote/activitypub/kernel/like.ts | 2 +- src/remote/activitypub/kernel/reject/follow.ts | 2 +- src/remote/activitypub/kernel/undo/block.ts | 2 +- src/remote/activitypub/kernel/undo/follow.ts | 2 +- src/remote/activitypub/kernel/undo/like.ts | 4 ++-- 8 files changed, 9 insertions(+), 9 deletions(-) (limited to 'src/remote/activitypub/kernel') diff --git a/src/remote/activitypub/kernel/accept/follow.ts b/src/remote/activitypub/kernel/accept/follow.ts index f3e517ad9f..377b8dac42 100644 --- a/src/remote/activitypub/kernel/accept/follow.ts +++ b/src/remote/activitypub/kernel/accept/follow.ts @@ -6,7 +6,7 @@ import { Users } from '../../../../models'; export default async (actor: IRemoteUser, activity: IFollow): Promise => { const id = typeof activity.actor == 'string' ? activity.actor : activity.actor.id; - if (id == null) throw 'missing id'; + if (id == null) throw new Error('missing id'); if (!id.startsWith(config.url + '/')) { return; diff --git a/src/remote/activitypub/kernel/block/index.ts b/src/remote/activitypub/kernel/block/index.ts index 19e33eb7dd..5c247326cb 100644 --- a/src/remote/activitypub/kernel/block/index.ts +++ b/src/remote/activitypub/kernel/block/index.ts @@ -9,7 +9,7 @@ const logger = apLogger; export default async (actor: IRemoteUser, activity: IBlock): Promise => { const id = typeof activity.object == 'string' ? activity.object : activity.object.id; - if (id == null) throw 'missing id'; + if (id == null) throw new Error('missing id'); const uri = activity.id || activity; diff --git a/src/remote/activitypub/kernel/follow.ts b/src/remote/activitypub/kernel/follow.ts index d37404502f..c255067bfd 100644 --- a/src/remote/activitypub/kernel/follow.ts +++ b/src/remote/activitypub/kernel/follow.ts @@ -6,7 +6,7 @@ import { Users } from '../../../models'; export default async (actor: IRemoteUser, activity: IFollow): Promise => { const id = typeof activity.object == 'string' ? activity.object : activity.object.id; - if (id == null) throw 'missing id'; + if (id == null) throw new Error('missing id'); if (!id.startsWith(config.url + '/')) { return; diff --git a/src/remote/activitypub/kernel/like.ts b/src/remote/activitypub/kernel/like.ts index d4fa7bf387..a08b453a89 100644 --- a/src/remote/activitypub/kernel/like.ts +++ b/src/remote/activitypub/kernel/like.ts @@ -5,7 +5,7 @@ import { Notes } from '../../../models'; export default async (actor: IRemoteUser, activity: ILike) => { const id = typeof activity.object == 'string' ? activity.object : activity.object.id; - if (id == null) throw 'missing id'; + if (id == null) throw new Error('missing id'); // Transform: // https://misskey.ex/notes/xxxx to diff --git a/src/remote/activitypub/kernel/reject/follow.ts b/src/remote/activitypub/kernel/reject/follow.ts index 91689339ab..d8b5a4b9b9 100644 --- a/src/remote/activitypub/kernel/reject/follow.ts +++ b/src/remote/activitypub/kernel/reject/follow.ts @@ -6,7 +6,7 @@ import { Users } from '../../../../models'; export default async (actor: IRemoteUser, activity: IFollow): Promise => { const id = typeof activity.actor == 'string' ? activity.actor : activity.actor.id; - if (id == null) throw 'missing id'; + if (id == null) throw new Error('missing id'); if (!id.startsWith(config.url + '/')) { return; diff --git a/src/remote/activitypub/kernel/undo/block.ts b/src/remote/activitypub/kernel/undo/block.ts index 9c277ed7d2..8ef70a9bef 100644 --- a/src/remote/activitypub/kernel/undo/block.ts +++ b/src/remote/activitypub/kernel/undo/block.ts @@ -9,7 +9,7 @@ const logger = apLogger; export default async (actor: IRemoteUser, activity: IBlock): Promise => { const id = typeof activity.object == 'string' ? activity.object : activity.object.id; - if (id == null) throw 'missing id'; + if (id == null) throw new Error('missing id'); const uri = activity.id || activity; diff --git a/src/remote/activitypub/kernel/undo/follow.ts b/src/remote/activitypub/kernel/undo/follow.ts index ce84d0c791..d75f055640 100644 --- a/src/remote/activitypub/kernel/undo/follow.ts +++ b/src/remote/activitypub/kernel/undo/follow.ts @@ -7,7 +7,7 @@ import { Users, FollowRequests, Followings } from '../../../../models'; export default async (actor: IRemoteUser, activity: IFollow): Promise => { const id = typeof activity.object == 'string' ? activity.object : activity.object.id; - if (id == null) throw 'missing id'; + if (id == null) throw new Error('missing id'); if (!id.startsWith(config.url + '/')) { return; diff --git a/src/remote/activitypub/kernel/undo/like.ts b/src/remote/activitypub/kernel/undo/like.ts index 75879d697a..2678828a9a 100644 --- a/src/remote/activitypub/kernel/undo/like.ts +++ b/src/remote/activitypub/kernel/undo/like.ts @@ -8,13 +8,13 @@ import { Notes } from '../../../../models'; */ export default async (actor: IRemoteUser, activity: ILike): Promise => { const id = typeof activity.object == 'string' ? activity.object : activity.object.id; - if (id == null) throw 'missing id'; + if (id == null) throw new Error('missing id'); const noteId = id.split('/').pop(); const note = await Notes.findOne(noteId); if (note == null) { - throw 'note not found'; + throw new Error('note not found'); } await deleteReaction(actor, note); -- cgit v1.2.3-freya