cxtioClient
.accounts(accountCode)
.messages()
.get(filter, function (err, data) {
if (err) {
logger.error("EmailScan - fetchEmailsWithFilter - fail to fetch the messages.");
callback(err, []);
return;
}
if (!data) {
var warning_message = "EmailScan - fetchEmailsWithFilter - fail to fetch any messages with filter = " + JSON.stringify(filter);
logger.warn(warning_message);
callback(null, []);
}
if (data.statusCode !== 200) {
handleNotOk(data, logger, callback);
return;
}
var msgBody = data.body;
logger.trace("EmailScan - fetchEmailsWithFilter - get the messages info with filter = " + JSON.stringify(filter));
logger.trace("EmailScan - fetchEmailsWithFilter - get response info = " + JSON.stringify(data));
logger.trace("EmailScan - fetchEmailsWithFilter - get message body = " + JSON.stringify(msgBody));
if (msgBody.length < 1) {
var warning_msg = "EmailScan - fetchEmailsWithFilter - fail to fetch any messages with filter = " + JSON.stringify(filter);
logger.warn(warning_msg);
callback(null, []);
return;
}
callback(null, msgBody);
});
}
function handleNotOk (data, logger, callback) {
//error handle, handle the error
logger.error("Unsuccessful response handle " + JSON.stringify(data));
var statusCode = 500;
if (data.statusCode !== undefined) {
statusCode = data.statusCode;
}
var err_obj = {"statusCode": statusCode, "message": data.body};
callback(err_obj, null);
}
I like the idea that my colleague change the exports part. Error Handling on the express.io controller
/*jslint node: true */
'use strict';
var HashMap = require('hashmap').HashMap;
var services = null;
module.exports = {
getAccountByEmail : function(req, res) {
//services
var emailscan = services.get('emailscan');
var logger = services.get('logger');