From 391ed435b9433ccd345652cc0fa47ce3d21e8d7d Mon Sep 17 00:00:00 2001 From: "barwie2@st.amu.edu.pl" Date: Mon, 9 Mar 2020 23:00:19 +0100 Subject: [PATCH] https post --- atcheck-websocket/server.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/atcheck-websocket/server.js b/atcheck-websocket/server.js index 3434fcf..9be4c77 100644 --- a/atcheck-websocket/server.js +++ b/atcheck-websocket/server.js @@ -24,28 +24,28 @@ var server = http.createServer(function (request, response) { }); request.on('end', function () { - body = JSON.parse(body); - var send_array = { - "type": "data", - "id": body.student_index, - "name": body.student_name, - "surname": body.student_surname, - "classes_code": body.classes_code - }; - lookup[body.classes_code].send(JSON.stringify(send_array)); - response.end("Added"); + try { + body = JSON.parse(body); + var send_array = { + "type": "data", + "id": body.student_index, + "name": body.student_name, + "surname": body.student_surname, + "classes_code": body.classes_code + }; + lookup[body.classes_code].send(JSON.stringify(send_array)); + response.end("Added"); + } catch (e) { + console.log(e); + } }); } else { - response.end("Undefined request."); + response.end("Undefined request ."); } }); -server.on('error', function (e) { - console.log(e); -}); - var http_port = 8889; server.listen(http_port); console.log("HTTP server running on port " + http_port);