From 9db5aff1c9b70821208389d1687b29036c6a938f Mon Sep 17 00:00:00 2001 From: Tim Robinson Date: Fri, 18 Sep 2015 10:59:54 +0000 Subject: [PATCH 1/4] When we can't stringify the error log it and tell the user, don't send them a stack trace --- plugins/c9.error/error_handler.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/c9.error/error_handler.js b/plugins/c9.error/error_handler.js index bd97e40a..da2c6227 100644 --- a/plugins/c9.error/error_handler.js +++ b/plugins/c9.error/error_handler.js @@ -120,6 +120,12 @@ function plugin(options, imports, register) { }; for (var prop in err) error[prop] = err[prop]; + try { + JSON.stringify(error); + } catch (e) { + console.error("Cannot send error as JSON: ", error); + error = "Unspecified error"; + } res.json({ error: error }, null, statusCode); // plain text } else { From 267ae6e3f46ca9860c130629c67fe5afc36e43bd Mon Sep 17 00:00:00 2001 From: Tim Robinson Date: Fri, 18 Sep 2015 11:02:19 +0000 Subject: [PATCH 2/4] Change the message --- plugins/c9.error/error_handler.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/c9.error/error_handler.js b/plugins/c9.error/error_handler.js index da2c6227..27b51b7a 100644 --- a/plugins/c9.error/error_handler.js +++ b/plugins/c9.error/error_handler.js @@ -124,7 +124,7 @@ function plugin(options, imports, register) { JSON.stringify(error); } catch (e) { console.error("Cannot send error as JSON: ", error); - error = "Unspecified error"; + error.message = "Unspecified error"; } res.json({ error: error }, null, statusCode); // plain text From 0d8fbef5d66fe5ffc62cc128887dce9e49bd075f Mon Sep 17 00:00:00 2001 From: Tim Robinson Date: Fri, 18 Sep 2015 11:02:50 +0000 Subject: [PATCH 3/4] It could be the scope breaking it --- plugins/c9.error/error_handler.js | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/c9.error/error_handler.js b/plugins/c9.error/error_handler.js index 27b51b7a..19d8052e 100644 --- a/plugins/c9.error/error_handler.js +++ b/plugins/c9.error/error_handler.js @@ -125,6 +125,7 @@ function plugin(options, imports, register) { } catch (e) { console.error("Cannot send error as JSON: ", error); error.message = "Unspecified error"; + error.scope = null; } res.json({ error: error }, null, statusCode); // plain text From 01746cac14e4e4ca78a94c1afd0e04544243f750 Mon Sep 17 00:00:00 2001 From: Tim Robinson Date: Fri, 18 Sep 2015 12:14:46 +0000 Subject: [PATCH 4/4] Have a nice error --- plugins/c9.error/error_handler.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/c9.error/error_handler.js b/plugins/c9.error/error_handler.js index 19d8052e..c1988c39 100644 --- a/plugins/c9.error/error_handler.js +++ b/plugins/c9.error/error_handler.js @@ -62,6 +62,8 @@ var statusCodes = { 510: "Not Extended", 511: "Network Authentication Required" }; + +var NICE_USER_ERROR_MSG = "Something went wrong. Please retry in a few minutes and contact support if it continues to occur"; function plugin(options, imports, register) { var connect = imports.connect; @@ -104,7 +106,7 @@ function plugin(options, imports, register) { res.setHeader('Content-Type', 'text/html; charset=utf-8'); res.render(path, { - title: statusCodes[statusCode] || "Unspecified Error", + title: statusCodes[statusCode] || NICE_USER_ERROR_MSG, scope: options.scope || "", showStackTrace: showStackTrace, stack: stack, @@ -124,7 +126,7 @@ function plugin(options, imports, register) { JSON.stringify(error); } catch (e) { console.error("Cannot send error as JSON: ", error); - error.message = "Unspecified error"; + error.message = NICE_USER_ERROR_MSG; error.scope = null; } res.json({ error: error }, null, statusCode);