diff --git a/lib/js/src/rpc/RpcStruct.js b/lib/js/src/rpc/RpcStruct.js index 44894174..30455f4d 100644 --- a/lib/js/src/rpc/RpcStruct.js +++ b/lib/js/src/rpc/RpcStruct.js @@ -130,19 +130,21 @@ class RpcStruct { * @param {Boolean} isArray - Whether or not the given variable is an array to be iterated through. */ _validateType (tClass, obj, isArray = false) { - if (isArray) { - if (!Array.isArray(obj)) { - throw new Error(`${obj.name} must be an array containing items of type ${tClass.name}`); - } else { - for (const item of obj) { - this._validateType(tClass, item, false); + if (obj !== null) { + if (isArray) { + if (!Array.isArray(obj)) { + throw new Error(`${obj.name} must be an array containing items of type ${tClass.name}`); + } else { + for (const item of obj) { + this._validateType(tClass, item, false); + } } + } else if ( + (tClass.prototype instanceof Enum && tClass.keyForValue(obj) === null) + || (tClass.prototype instanceof RpcStruct && obj.constructor !== tClass) + ) { + throw new Error(`${obj.name} must be of type ${tClass.name}`); } - } else if ( - (tClass.prototype instanceof Enum && tClass.keyForValue(obj) === null) - || (tClass.prototype instanceof RpcStruct && obj !== null && obj.constructor !== tClass) - ) { - throw new Error(`${obj.name} must be of type ${tClass.name}`); } } }