From c044ca14f5121ca67583855cd7f53ba1008d9f95 Mon Sep 17 00:00:00 2001 From: nightwing Date: Mon, 27 Feb 2017 19:02:39 +0400 Subject: [PATCH 1/5] do not show ENOENT errors in browser console --- node_modules/vfs-http-adapter/restful.js | 6 ++++-- plugins/c9.core/http-xhr.js | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/node_modules/vfs-http-adapter/restful.js b/node_modules/vfs-http-adapter/restful.js index 3bf1646b..79166442 100644 --- a/node_modules/vfs-http-adapter/restful.js +++ b/node_modules/vfs-http-adapter/restful.js @@ -10,7 +10,9 @@ module.exports = function setup(mount, vfs, mountOptions) { if (!mountOptions) mountOptions = {}; var errorHandler = mountOptions.errorHandler || function (req, res, err, code) { - console.error(err.stack || err); + // do not show ENOENT errors in browser console + if (err.code != "ENOENT") + console.error(err.stack || err); if (res.headersSent) { res.end(""); return; @@ -20,7 +22,7 @@ module.exports = function setup(mount, vfs, mountOptions) { else if (typeof err.code == "number" && isValidStatusCode(err.code)) res.statusCode = err.code; else if (err.code === "EBADREQUEST") res.statusCode = 400; else if (err.code === "EACCES") res.statusCode = 403; - else if (err.code === "ENOENT") res.statusCode = 404; + else if (err.code === "ENOENT") res.statusCode = 208; else if (err.code === "ENOTREADY") res.statusCode = 503; else if (err.code === "EISDIR") res.statusCode = 503; else res.statusCode = 500; diff --git a/plugins/c9.core/http-xhr.js b/plugins/c9.core/http-xhr.js index 378d68af..66285110 100644 --- a/plugins/c9.core/http-xhr.js +++ b/plugins/c9.core/http-xhr.js @@ -119,11 +119,11 @@ define(function(require, module, exports) { } } - if (this.status > 299) { + if (xhr.status > 299 || xhr.status == 208) { var err = new Error(xhr.responseText); err.code = xhr.status; - if (debug) - console.error("HTTP error " + this.status + ": " + xhr.responseText); + if (debug && xhr.status > 299) + console.error("HTTP error " + xhr.status + ": " + xhr.responseText); return done(err, data, res); } From 2013650781b399ed7cb67e4837dd2c91abf39890 Mon Sep 17 00:00:00 2001 From: nightwing Date: Thu, 6 Apr 2017 21:51:30 +0400 Subject: [PATCH 2/5] use special content-type instead of 208 status code --- node_modules/vfs-http-adapter/restful.js | 4 ++-- plugins/c9.core/http-xhr.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/node_modules/vfs-http-adapter/restful.js b/node_modules/vfs-http-adapter/restful.js index 79166442..55a19ad8 100644 --- a/node_modules/vfs-http-adapter/restful.js +++ b/node_modules/vfs-http-adapter/restful.js @@ -22,12 +22,12 @@ module.exports = function setup(mount, vfs, mountOptions) { else if (typeof err.code == "number" && isValidStatusCode(err.code)) res.statusCode = err.code; else if (err.code === "EBADREQUEST") res.statusCode = 400; else if (err.code === "EACCES") res.statusCode = 403; - else if (err.code === "ENOENT") res.statusCode = 208; + else if (err.code === "ENOENT") res.statusCode = 200; else if (err.code === "ENOTREADY") res.statusCode = 503; else if (err.code === "EISDIR") res.statusCode = 503; else res.statusCode = 500; var message = (err.message || err.toString()) + "\n"; - res.setHeader("Content-Type", "text/plain"); + res.setHeader("Content-Type", "text/x-error"); res.setHeader("Content-Length", Buffer.byteLength(message)); res.end(message); }; diff --git a/plugins/c9.core/http-xhr.js b/plugins/c9.core/http-xhr.js index 66285110..5293b99a 100644 --- a/plugins/c9.core/http-xhr.js +++ b/plugins/c9.core/http-xhr.js @@ -119,7 +119,7 @@ define(function(require, module, exports) { } } - if (xhr.status > 299 || xhr.status == 208) { + if (xhr.status > 299 || res.headers["content-type"] == "text/x-error") { var err = new Error(xhr.responseText); err.code = xhr.status; if (debug && xhr.status > 299) From b909151a8970009271516ce5d845bb5b3d835927 Mon Sep 17 00:00:00 2001 From: Harutyun Amirjanyan Date: Fri, 7 Apr 2017 14:14:06 +0400 Subject: [PATCH 3/5] add comment --- node_modules/vfs-http-adapter/restful.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node_modules/vfs-http-adapter/restful.js b/node_modules/vfs-http-adapter/restful.js index 55a19ad8..7eea63c0 100644 --- a/node_modules/vfs-http-adapter/restful.js +++ b/node_modules/vfs-http-adapter/restful.js @@ -22,7 +22,7 @@ module.exports = function setup(mount, vfs, mountOptions) { else if (typeof err.code == "number" && isValidStatusCode(err.code)) res.statusCode = err.code; else if (err.code === "EBADREQUEST") res.statusCode = 400; else if (err.code === "EACCES") res.statusCode = 403; - else if (err.code === "ENOENT") res.statusCode = 200; + else if (err.code === "ENOENT") res.statusCode = 200; // don't trigger error in browser (rely on Content-Type) else if (err.code === "ENOTREADY") res.statusCode = 503; else if (err.code === "EISDIR") res.statusCode = 503; else res.statusCode = 500; From ab85ed03688a6cce4912dd0e816737f22a45449b Mon Sep 17 00:00:00 2001 From: nightwing Date: Sat, 8 Apr 2017 16:08:04 +0400 Subject: [PATCH 4/5] remove unused href from readdir results --- node_modules/vfs-http-adapter/restful.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/node_modules/vfs-http-adapter/restful.js b/node_modules/vfs-http-adapter/restful.js index 7eea63c0..ca4c8568 100644 --- a/node_modules/vfs-http-adapter/restful.js +++ b/node_modules/vfs-http-adapter/restful.js @@ -42,13 +42,6 @@ module.exports = function setup(mount, vfs, mountOptions) { output.readable = true; var first = true; input.on("data", function (entry) { - if (path) { - entry.href = path + entry.name; - var mime = entry.linkStat ? entry.linkStat.mime : entry.mime; - if (/(directory|folder)$/.test(mime)) { - entry.href += "/"; - } - } if (first) { output.emit("data", "[\n " + JSON.stringify(entry)); first = false; From 274deff369210ab1ab0a901dff739403e6649c81 Mon Sep 17 00:00:00 2001 From: nightwing Date: Sat, 8 Apr 2017 16:09:08 +0400 Subject: [PATCH 5/5] fix preview handler --- plugins/c9.preview/preview.handler.js | 2 +- plugins/c9.preview/views/listing.html.ejs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/c9.preview/preview.handler.js b/plugins/c9.preview/preview.handler.js index ad09b407..d2e9839e 100644 --- a/plugins/c9.preview/preview.handler.js +++ b/plugins/c9.preview/preview.handler.js @@ -167,7 +167,7 @@ define(function(require, exports, module) { port: parsedUrl.port, headers: req.headers }, function(request) { - if (request.statusCode >= 400) + if (request.statusCode >= 400 || request.headers["content-type"] == "text/x-error") handleError(request); else if (isDir) serveListing(request); diff --git a/plugins/c9.preview/views/listing.html.ejs b/plugins/c9.preview/views/listing.html.ejs index d344db98..6c1c5d3b 100644 --- a/plugins/c9.preview/views/listing.html.ejs +++ b/plugins/c9.preview/views/listing.html.ejs @@ -1,6 +1,7 @@ + Cloud9 Preview @@ -24,7 +25,7 @@ - <%= entry.name %> + <%= entry.name %> <%= entry.mime %> <%= entry.size %>