-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidateInput.js
30 lines (28 loc) · 1007 Bytes
/
validateInput.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { log } from "./log.js";
// function isCorrect( field ) {
// return typeof field === "string" && !!field.length;
// }
export function validateInput( input ) {
let isOK = false;
let body;
let info = "";
const bodystring = input.toString();
try {
body = JSON.parse( bodystring );
if ( typeof body === "object" /* other checks */ ) {
isOK = true;
log( "В сокет пришло: ", body );
} else {
info = "Некорректная структура запроса: " + bodystring;
log( "Некорректная структура запроса: ", body );
}
// if ( !isCorrect( body.command ) ) {
// info = "Вы не ввели G команду.";
// }
} catch ( error ) {
info = "Ошибка при парсинге JSON запроса: " + bodystring;
log( info );
log( "error: ", error );
}
return { isOK, info, body };
}