I’m trying to perform some server-side validation via the EventScripts and am getting some strange behavior.
I have DSP connected to an RDS instance of SQL Server. On the POST.pre_process
event for one of my endpoints I’m trying to test if several properties exists and if they are populated. An example would be:
var record = event.request.body.record;
if (!_.has(record, "myProp") {
throw 'myProp is a required field';
}
if (record.myProp.length === 0) {
throw 'myProp is a required field';
}
When I try to run this I get an Internal.server.error
from DSP. I tried throwing _.has(record, "myProp")
to see what it was returning. If I pass a valid property the function returns 1
. If I pass an invalid property (anything that doesn’t exist) DSP throws an Internal.server.error
with no further details. I’ve also tried record.hasOwnProperty('myProp')
and get the same behavior.
It seems that the issue is possibly related to anything returning a falsey value. If put throw 1===0;
in there I get Internal.server.error
. If I put throw 1===1;
I get back 1
Any ideas on what’s going on here?