On 01/11/14 08:50, Jiayu Liu wrote:
I tried to request server by ajax, but console just gave me 500 status code if
there are some bugs of my code. That's so inconvenient that I try to fix that 
bug.
Is there any approach to print the err stack when I request by ajax?

I guess you want to have the stack trace displayed on the client (which is ti be avoided, since you may give away details of your system that might be exploited by malicious users).

Anyway, this would do:

require("http").createServer(function (req, res) {
  try {
    xxx;
  } catch(e) {
    res.writeHead(500, { "Content-Type": "text/plain"});
    res.write("Status: " + res.statusCode + "\n");
    res.write("Message: " +e.message + "\n");
    res.write("Stacktrace: "  + e.stack + "\n");
    res.end();
    return;
  }
  res.writeHead(200, { "Content-Type": "text/plain"});
  res.end("OK");
}).listen(8080, "127.0.0.1");

console.log("Server running at http://127.0.0.1:8080/";);

Regards,

Luca Morandini
Data Architect - AURIN project
Melbourne eResearch Group
Department of Computing and Information Systems
University of Melbourne
Tel. +61 03 903 58 380
Skype: lmorandini

--
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/m3258h%24f5k%241%40ger.gmane.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to