Internal.server.error when returning falsey values

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?

This appears to be a bug. I can get truthy values all day long

throw true;
throw 1;

And I can throw strings

throw "true";
throw "false";
throw "a fit";

But if I throw anything falsey

throw 0;
throw false;

I see the same internal server error rather than the specified throw.

It appears this is a bug.

Well at least I know it’s not me! Thanks @jeffreystables!

Being as you responded ~14m ago I’m guessing you have no idea on a time-table for a fix? :smile:

I have created GitHub Issue #51 for this problem, so you can easily track its progress.

https://github.com/dreamfactorysoftware/dsp-core/issues/51

Any timeline or planned release should be posted to that Issue thread by the developers. We are planning a new release very soon, and I expect they will want to fix this in that release.

Thanks @jeffreystables I’ll follow that issue on GitHub.

This has been fixed and included in the develop branch. It will be included in the next release.