Skip to content

Commit

Permalink
manage fatal error with email
Browse files Browse the repository at this point in the history
  • Loading branch information
evaletolab committed Oct 29, 2014
1 parent e11b59d commit b9662e2
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions app/bus.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ onTrace=function(token,error){

};

onMessage=function(token,content){
onMessage=function(title,content){
var msg=JSON.stringify(content,null,2);
bus.emit( "sendmail",
"[email protected]","[kariboo-subscribe] : "+content.email,
"[email protected]",title,
{content:msg}, "simple");

};
Expand Down
2 changes: 1 addition & 1 deletion controllers/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ exports.message = function(req, res) {
if(origins.indexOf(req.params.key)==-1){
// return res.send(401,"invalid token")
}
bus.emit('system.message',req.params.key,req.body);
bus.emit('system.message',"[kariboo-subscribe] : ",req.body);

res.json({});
};
9 changes: 5 additions & 4 deletions controllers/orders.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,11 @@ exports.create=function(req,res){
transaction.process(card, function(err,result){
if(err){
return order.rollbackProductQuantityAndSave(function(e){
if(err){
//FIXME
console.log("-------------------------------pf",err)
console.log("-------------------------------mg",e)
if(e){

//
//DANGER on
bus.emit('system.message',"[kariboo-danger] : ",{error:e,order:o.oid,customer:o.email});
}
return res.json(400,err.message)
});
Expand Down
8 changes: 6 additions & 2 deletions models/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,12 @@ Orders.methods.rollbackProductQuantityAndSave=function(callback){
db.model('Products').update({sku:item.sku},{$inc: {"pricing.stock":item.quantity}}, { safe: true }, cb)
},function(err){
if(err){
callback(err);
throw new Error("rollback: "+(err.message||err));

//
//DANGER send email
bus.emit('system.message',"[kariboo-danger] : ",{error:err,order:self.oid,customer:self.email});

return callback(err);
}

//
Expand Down
2 changes: 0 additions & 2 deletions models/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -648,9 +648,7 @@ UserSchema.statics.addPayment=function(id, payment,callback){
safePayment.expiry=payment.expiry;
safePayment.updated=Date.now();

console.log('1 alias',alias)
card.publish({alias:alias},function(err,res){
console.log('2 publish err',err, res)
if(err){
return callback(err.message)
}
Expand Down

0 comments on commit b9662e2

Please sign in to comment.