How to print the error stack when I request by ajax

28 views
Skip to first unread message

Jiayu Liu

unread,
Oct 31, 2014, 5:50:12 PM10/31/14
to nod...@googlegroups.com
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?

Luca Morandini

unread,
Nov 1, 2014, 12:43:16 PM11/1/14
to nod...@googlegroups.com
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

Adrian Lynch

unread,
Nov 1, 2014, 12:46:51 PM11/1/14
to nod...@googlegroups.com
Do you have access to the server as well? If so, view the error in the console.

If you have no control of the server then you're most likely out of luck.

Adrian

On 31 October 2014 21:50, Jiayu Liu <vincent...@gmail.com> 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?

--
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 nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/a03bb99d-4132-458d-bc74-7fd13b98ea1a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages