From f27dd1c67326f94db0e6f9177bcb83ee92b8c161 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 5 Aug 2018 21:19:06 +0900 Subject: [PATCH] Fix bug --- src/back.ts | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/back.ts b/src/back.ts index a32d352..30f3d92 100644 --- a/src/back.ts +++ b/src/back.ts @@ -142,7 +142,7 @@ class Session { /** * 対局が終わったとき */ - private onEnded = (msg: any) => { + private onEnded = async (msg: any) => { // ストリームから切断 process.send({ type: 'close' @@ -178,7 +178,7 @@ class Session { } } - this.post(text, this.startedNote ? this.startedNote.id : null); + await this.post(text, this.startedNote); process.exit(); } @@ -363,15 +363,25 @@ class Session { */ private post = async (text: string, renote?: any) => { if (this.allowPost) { - const res = await request.post(`${config.host}/api/notes/create`, { - json: { - i: config.i, - text: text, - renoteId: renote ? renote.id : undefined - } - }); + const body = { + i: config.i, + text: text + } as any; - return res.createdNote; + if (renote) { + body.renoteId = renote.id; + } + + try { + const res = await request.post(`${config.host}/api/notes/create`, { + json: body + }); + + return res.createdNote; + } catch (e) { + console.error(e); + return null; + } } else { return null; }