me@helium 8 лет назад
Родитель
Сommit
4f30940c21
1 измененных файлов с 17 добавлено и 6 удалено
  1. 17 6
      chatServer/server.js

+ 17 - 6
chatServer/server.js

@@ -4,10 +4,11 @@ var history = [];
 var messageId = 0;
 
 var errorMessages = {
-   0: "All fine",
-   -1: "No space left in DB",
-   -2: "Wrong data",
-   -3: "Apocalypse"
+   "0": "All fine",
+   "-1": "No space left in DB",
+   "-2": "Wrong data",
+   "-3": "Apocalypse",
+   "-4": "REALLY Wrong data",
 };
 
 var RPCFuncs = {
@@ -28,9 +29,19 @@ server = http.createServer(function(req, res){
                 body += data;
         });
         req.on('end', function () {
-                console.log("Body: " + body);
-                data = JSON.parse(body);
+                //console.log("Body: " + body);
+                //try{
+                    //data = JSON.parse(body);
+                //}
+                //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]}));
                 if ("func" in data){
                     if (data.func in RPCFuncs){
                         var func = data.func;