Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion api/utils/common.js
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think with this update, if params is not passed to the function, request will just hang since there's nothing ending "res".
to me, completely removing the nullcheck for params from the if condition would be the best approach here

Original file line number Diff line number Diff line change
Expand Up @@ -1522,6 +1522,11 @@ common.unblockResponses = function(params) {
* @param {object} heads - headers to add to the output
*/
common.returnRaw = function(params, returnCode, body, heads) {
if (!params) {
console.error("Params is null or undefined, cannot proceed.");
return;
}

params.response = {
code: returnCode,
body: body
Expand Down Expand Up @@ -1569,6 +1574,11 @@ common.returnRaw = function(params, returnCode, body, heads) {
* @param {boolean} noResult - skip wrapping message object into stupid {result: }
*/
common.returnMessage = function(params, returnCode, message, heads, noResult = false) {
if (!params) {
console.error("Params is null or undefined, cannot proceed.");
return;
}

params.response = {
code: returnCode,
body: JSON.stringify(noResult && typeof message === 'object' ? message : {result: message}, escape_html_entities)
Expand Down Expand Up @@ -2629,7 +2639,7 @@ common.updateAppUser = function(params, update, no_meta, callback) {
callback = no_meta;
no_meta = false;
}
if (Object.keys(update).length) {
if (update && Object.keys(update).length) {
for (var i in update) {
if (i.indexOf("$") !== 0) {
let err = "Unkown modifier " + i + " in " + update + " for " + params.href;
Expand Down
Loading