lisk-sdk
lisk-sdk copied to clipboard
validateTransaction return types (LiskValidationError | Error | undefined) not needed
Description
export const validateTransaction = (
transactionObject: Record<string, unknown>,
paramsSchema?: object,
): LiskValidationError | Error | undefined => {
const transactionObjectWithEmptyParameters = {
...transactionObject,
params: Buffer.alloc(0),
};
validator.validate(baseTransactionSchema, transactionObjectWithEmptyParameters);
if (!paramsSchema) {
return undefined;
}
if (typeof transactionObject.params !== 'object' || transactionObject.params === null) {
return new Error('Transaction object params must be of type object and not null');
}
validator.validate(paramsSchema, transactionObject.params);
return undefined;
};
Usage:
const validationErrors = validateTransaction(transactionObject, paramsSchema);
if (validationErrors) {
throw validationErrors;
}
If we look at the usageS of this function, we can see that it checks if there are any errors returned, if yes ,then they are thrown instantly. We can rather remove these throw statements at all such usages & result will be the same.
Motivation
If validateTransaction can throw errors inside it's body, then we don't need to throw them outside.