Joel
Joel

Reputation: 16134

Node domains on Azure Mobile Services

I can't seem to get domains to work on Azure Mobile Services (ZUMO). For example:

var myDomain = require('domain').create();
myDomain.on('error', function ()
{
    console.log('got here');
});

myDomain.run(function() {
    boo(); //throws
});

The on error handler of my domain will never get called. This exception will be caught by ZUMO and their 500 error will get returned. I'd prefer to trap the exception myself, log it, and return a 500 using my preferred JSON format. I realize that there is some global error trapping that ZUMO is doing but I would think that if I have a domain it should catch it before it bubbles up to the ZUMO wrapper. Any suggestions?

(ZUMO runs on Node 0.8.28)

Upvotes: 0

Views: 49

Answers (1)

Dale Anderson
Dale Anderson

Reputation: 1701

The code you list will handle uncaught exceptions. Mobile Services scripts and the underlying async data operations are wrapped in try..catch blocks, so they will not invoke a domain error handler.

You should be handling errors in your scripts using normal error handling practices, i.e. try..catch blocks or error handling callbacks for promises. You can then return the appropriate response using res.send.

Upvotes: 2

Related Questions