From 9f0b8ba2f89fd303c49f9edeccdaa8ea4ad4146b Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Tue, 13 Nov 2018 19:34:09 +0900 Subject: [PATCH] Fix: notes/create hangs when rejected (#3221) --- src/server/api/call.ts | 2 +- src/server/api/endpoints/notes/create.ts | 18 ++++++++++-------- src/services/note/create.ts | 10 +++++----- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/server/api/call.ts b/src/server/api/call.ts index 900b77e680..6252537c0e 100644 --- a/src/server/api/call.ts +++ b/src/server/api/call.ts @@ -56,7 +56,7 @@ export default (endpoint: string, user: IUser, app: IApp, data: any, file?: any) console.warn(`SLOW API CALL DETECTED: ${ep.name} (${time}ms)`); } } catch (e) { - if (e.name == 'INVALID_PARAM') { + if (e && e.name == 'INVALID_PARAM') { rej({ code: e.name, param: e.param, diff --git a/src/server/api/endpoints/notes/create.ts b/src/server/api/endpoints/notes/create.ts index 4f031aa43d..a7050e2ec2 100644 --- a/src/server/api/endpoints/notes/create.ts +++ b/src/server/api/endpoints/notes/create.ts @@ -216,7 +216,7 @@ export default define(meta, (ps, user, app) => new Promise(async (res, rej) => { } // 投稿を作成 - const note = await create(user, { + create(user, { createdAt: new Date(), files: files, poll: ps.poll, @@ -229,12 +229,14 @@ export default define(meta, (ps, user, app) => new Promise(async (res, rej) => { visibility: ps.visibility, visibleUsers, geo: ps.geo - }); - - const noteObj = await pack(note, user); - - // Reponse - res({ - createdNote: noteObj + }) + .then(note => pack(note, user)) + .then(noteObj => { + res({ + createdNote: noteObj + }); + }) + .catch(e => { + rej(e); }); })); diff --git a/src/services/note/create.ts b/src/services/note/create.ts index bd38605fda..53d51036b3 100644 --- a/src/services/note/create.ts +++ b/src/services/note/create.ts @@ -116,27 +116,27 @@ export default async (user: IUser, data: Option, silent = false) => new Promise< // リプライ対象が削除された投稿だったらreject if (data.reply && data.reply.deletedAt != null) { - return rej(); + return rej('Reply target has been deleted'); } // Renote対象が削除された投稿だったらreject if (data.renote && data.renote.deletedAt != null) { - return rej(); + return rej('Renote target has been deleted'); } // Renote対象が「ホームまたは全体」以外の公開範囲ならreject if (data.renote && data.renote.visibility != 'public' && data.renote.visibility != 'home') { - return rej(); + return rej('Renote target is not public or home'); } // リプライ対象が自分以外の非公開の投稿なら禁止 if (data.reply && data.reply.visibility == 'private' && !data.reply.userId.equals(user._id)) { - return rej(); + return rej('Reply target is private of others'); } // Renote対象が自分以外の非公開の投稿なら禁止 if (data.renote && data.renote.visibility == 'private' && !data.renote.userId.equals(user._id)) { - return rej(); + return rej('Renote target is private of others'); } if (data.text) {