You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 29, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Jul 29, 2026. It is now read-only.
saveUpdates function in server controllers does not handle null properly #2052
But if the entity is null, then the return of the merge (the updated variable) will not be a Mongoose doc. Then, when updated.save() is called, it will throw a save is a not a function of null error. To fix, saveUpdates should be wrapped in an if statement:
Activity
Awk34 commentedon Jul 11, 2016
handleEntityNotFoundshouldn't be returningnullwkevwang commentedon Jul 11, 2016
If the entity is not found, the query returns null, and then
handleEntityNotFoundwill return null as seen here:Awk34 commentedon Jul 13, 2016
Hmm, the way this is set up might be need to be rethought... but for now, I think your suggestion is best. I would welcome a PR.
fix(endpoint:controller): wrap saveUpdates in an if(entity) statement