Ivan Asmer il y a 8 ans
Parent
commit
34f0817d10
1 fichiers modifiés avec 8 ajouts et 8 suppressions
  1. 8 8
      chatServer/server.js

+ 8 - 8
chatServer/server.js

@@ -30,15 +30,15 @@ server = http.createServer(function(req, res){
         });
         req.on('end', function () {
                 console.log("Body: " + body);
-                //try{
+                try{
                     data = JSON.parse(body);
-                //}
-                //catch (e){
-                    //console.log("wrong JSON");
-                    //var errorCode = -4;
-                    //res.end(JSON.stringify({errorCode: errorCode, errorMessage: errorMessages[errorCode]}));
-                    //return;
-                //}
+                }
+                catch (e){
+                    console.log("wrong JSON");
+                    var errorCode = -4;
+                    res.end(JSON.stringify({errorCode: errorCode, errorMessage: errorMessages[errorCode]}));
+                    return;
+                }
                 var timestamp =(new Date()).getTime(); 
                 //var errorCode = 0 - Math.floor(Math.random()*4)
                 //res.end(JSON.stringify({errorCode: errorCode, errorMessage: errorMessages[errorCode]}));