From b334066f8f0f93134ac58413a91542de4145accc Mon Sep 17 00:00:00 2001 From: Dessa Simpson Date: Sat, 19 Sep 2020 18:14:58 -0700 Subject: [PATCH] Improve error reporting Fixes #16 --- public/main.js | 2 +- src/app.ts | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/public/main.js b/public/main.js index 2a92bdc..6dbb63c 100644 --- a/public/main.js +++ b/public/main.js @@ -110,7 +110,7 @@ function addVote(url) { })}) .then(response => { if (!response.ok) { - response.text().then(addRequestErr); + response.text().then(showMessage); return; } updateTable(); diff --git a/src/app.ts b/src/app.ts index d1d7a9d..a2e9209 100644 --- a/src/app.ts +++ b/src/app.ts @@ -72,7 +72,7 @@ app.post("/api/addRequest", async (request, response) => { if (request.session) await validateApiToken(request.session); if (!request.session || !request.session.user) { response.status(401); - response.send("Must be logged in"); + response.send("Session expired; please log in again"); return; } var banned = await db.query(Object.assign(queries.checkBan, { values: [request.session.user.id] })).then((result: pg.QueryResult) => result.rowCount > 0); @@ -99,7 +99,7 @@ app.post("/api/updateRequestState", async (request, response) => { if (request.session) await validateApiToken(request.session); if (!request.session || !request.session.user) { response.status(401); - response.send("Must be logged in"); + response.send("Session expired; please log in again"); return; } var streamerid = await db.query(queries.getStreamerId).then((result: pg.QueryResult) => result.rows[0]['userid']); @@ -132,7 +132,7 @@ app.post("/api/updateRequestScore", async (request, response) => { if (request.session) await validateApiToken(request.session); if (!request.session || !request.session.user) { response.status(401); - response.send("Must be logged in"); + response.send("Session expired; please log in again"); return; } var streamerid = await db.query(queries.getStreamerId).then((result: pg.QueryResult) => result.rows[0]['userid']); @@ -165,7 +165,7 @@ app.post("/api/deleteRequest", async (request, response) => { if (request.session) await validateApiToken(request.session); if (!request.session || !request.session.user) { response.status(401); - response.send("Must be logged in"); + response.send("Session expired; please log in again"); return; } var streamerid = await db.query(queries.getStreamerId).then((result: pg.QueryResult) => result.rows[0]['userid']); @@ -193,7 +193,7 @@ app.post("/api/addVote", async (request,response) => { if (request.session) await validateApiToken(request.session); if (!request.session || !request.session.user) { response.status(401); - response.send("Must be logged in"); + response.send("Session expired; please log in again"); return; } var banned = await db.query(Object.assign(queries.checkBan,{ values: [request.session.user.id] })).then((result: pg.QueryResult) => result.rowCount > 0); @@ -221,7 +221,7 @@ app.post("/api/deleteVote", async (request,response) => { if (request.session) await validateApiToken(request.session); if (!request.session || !request.session.user) { response.status(401); - response.send("Must be logged in"); + response.send("Session expired; please log in again"); return; } if (!request.body.url) {