code: function validateJSONResponse(resp, result_schema) {
  
     const ajv = new Ajv();
     if (result_schema) {
        try {
           const valid = ajv.validate(result_schema, resp);
           assert(valid);
           return resp;
        }
        catch(e) {
           try {
              // error message
              const valid = ajv.validate(CORE_ERROR_SCHEMA, resp);
              assert(valid);
              return resp;
           }
           catch(e2) {
              console.log("Failed to validate with desired schema");
              console.log(e.stack);
              console.log("Failed to validate with error schema");
              console.log(e2.stack);
              console.log("Desired schema:");
              console.log(result_schema);
              console.log("Parsed message:");
              console.log(resp);
              throw new Error("Invalid core message");
           }
        }
     }
     else {
        return resp;
     }
  }
docs: /*
  Helper method to validate a JSON response
  against a schema.  Returns the validated object
  on success, and throw an exception on error.