message: Add wrapJson functions for DebugApi
diff: @@ -201,4 +201,36 @@ DebugApi.prototype.run = function() {
  }).listen(this.port);
  }
  +DebugApi.prototype._wrapJsonReq = function(req, response) {
  + let body = "";
  + req.on("data", function(chunk) {
  + body += chunk;
  + });
  + return new Promise((resolve, reject) => {
  + req.on("error", (err) => {
  + reject(err);
  + });
  + req.on("end", () => {
  + if( body === "") {
  + reject({"error": "Body missing"});
  + }
  + try {
  + body = JSON.parse(body);
  + resolve(
  + body
  + );
  + }
  + catch (err) {
  + reject(err);
  + }
  + });
  + });
  +}
  +
  +DebugApi.prototype._wrapJsonResponse = function(json, isOk, response) {
  + response.writeHead(isOk === true ? 200 : 500, {"Content-Type": "application/json"});
  + response.write(JSON.stringify(json));
  + response.end();
  +}
  +
  module.exports = DebugApi;
  