Skip to content

Instantly share code, notes, and snippets.

@azat-co
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azat-co/67509d5c8e38d2f5f4dd to your computer and use it in GitHub Desktop.
Save azat-co/67509d5c8e38d2f5f4dd to your computer and use it in GitHub Desktop.
var sendHipChatMessage = function(message, callback) {
var fromhost = server
.set('hostname')
.replace('-','')
.substr(0, 15); //truncate the string
try {
message = JSON.stringify(message);
} catch(e) {}
var data = {
'format': 'json',
auth_token: server.config.keys.hipchat.servers,
room_id: server.config.keys.hipchat.serversRoomId,
from: fromhost,
message: 'v'
+ server.set('version')
+ '\nmessage: '
+ message
};
request({
url:'http://api.hipchat.com/v1/rooms/message',
method:'POST',
qs: data}, function (e, r, body) {
if (e) console.error(e);
if (callback) return callback();
});
};
 
server.notify = {};
server.notify.error = function(e) {
var message = e.stack || e.message || e.name || e;
sendHipChatMessage(message);
console.error(message);
server.sendgrid.email({
to: 'error@webapplog.com',
from: server.set('hostname') + '@webapplog.com',
subject: 'Webapp '
+ server.set('version')
+ ' error: "'
+ e.name
+ '"',
category: 'webapp-error',
text: e.stack || e.message
}, exit);
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment