diff --git a/lib/helpers.js b/lib/helpers.js index 04f9d07..23d5d48 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -44,12 +44,10 @@ function store_skin(rid, userId, profile, cache_details, callback) { } else { skins.save_image(img, skinpath, function(skin_err) { if (skin_err) { - logging.error(rid, skin_err); callback(skin_err, null); } else { skins.extract_face(img, facepath, function(err2) { if (err2) { - logging.error(rid, err2.stack); callback(err2, null); } else { logging.debug(rid, "face extracted"); @@ -95,7 +93,6 @@ function store_cape(rid, userId, profile, cache_details, callback) { } else { networking.get_from(rid, url, function(img, response, net_err) { if (net_err || !img) { - logging.error(rid, net_err.stack); callback(net_err, null); } else { skins.save_image(img, capepath, function(skin_err) { @@ -342,10 +339,7 @@ exp.get_render = function(rid, userId, scale, helm, body, callback) { callback(null, 0, skin_hash, null); } else { fs.writeFile(renderpath, drawn_img, "binary", function(fs_err) { - if (fs_err) { - logging.error(rid, fs_err.stack); - } - callback(null, 2, skin_hash, drawn_img); + callback(fs_err, 2, skin_hash, drawn_img); }); } }); diff --git a/lib/networking.js b/lib/networking.js index 0217d12..3c427c7 100644 --- a/lib/networking.js +++ b/lib/networking.js @@ -73,12 +73,9 @@ exp.get_from_options = function(rid, url, options, callback) { }, function(error, response, body) { // log url + code + description var code = response && response.statusCode; - if (error) { - logging.error(rid, url, error); - } else { - var logfunc = code && code < 405 ? logging.debug : logging.warn; - logfunc(rid, url, code, http_code[code]); - } + + var logfunc = code && code < 405 ? logging.debug : logging.warn; + logfunc(rid, url, code, http_code[code]); switch (code) { @@ -201,7 +198,6 @@ exp.save_texture = function(rid, tex_hash, outpath, callback) { var textureurl = textures_url + tex_hash; exp.get_from(rid, textureurl, function(img, response, err) { if (err) { - logging.error(rid, "error while downloading texture"); callback(err, response, null); } else { skins.save_image(img, outpath, function(img_err) { diff --git a/lib/renders.js b/lib/renders.js index 2d0cc26..af7940c 100644 --- a/lib/renders.js +++ b/lib/renders.js @@ -161,7 +161,6 @@ exp.draw_model = function(rid, img, scale, helm, body, callback) { var image = new Image(); image.onerror = function(err) { - logging.error(rid, "render error:", err.stack); callback(err, null); }; @@ -189,9 +188,6 @@ exp.draw_model = function(rid, img, scale, helm, body, callback) { enhance(model_ctx); model_canvas.toBuffer(function(err, buf) { - if (err) { - logging.error(rid, "error creating buffer:", err); - } callback(err, buf); }); }; @@ -203,9 +199,6 @@ exp.draw_model = function(rid, img, scale, helm, body, callback) { // callback: error, image buffer exp.open_render = function(rid, renderpath, callback) { fs.readFile(renderpath, function(err, buf) { - if (err) { - logging.error(rid, "error while opening skin file:", err); - } callback(err, buf); }); }; diff --git a/lib/response.js b/lib/response.js index 09a703a..8403ded 100644 --- a/lib/response.js +++ b/lib/response.js @@ -12,6 +12,9 @@ var human_status = { }; +// print these, but without stacktrace +var silent_errors = ["ETIMEDOUT", "ESOCKETTIMEDOUT", "ECONNRESET", "EHOSTUNREACH", "ECONNREFUSED"]; + // handles HTTP responses // +request+ a http.IncomingMessage // +response+ a http.ServerResponse @@ -23,7 +26,6 @@ var human_status = { // * hash: image hash, required when body is an image // * err: a possible Error module.exports = function(request, response, result) { - response.on("close", function() { logging.warn(request.id, "Connection closed"); }); @@ -38,7 +40,7 @@ module.exports = function(request, response, result) { // These headers are the same for every response var headers = { - "Content-Type": (result.body && result.type) || "text/plain", + "Content-Type": result.body && result.type || "text/plain", "Cache-Control": "max-age=" + config.caching.browser + ", public", "Response-Time": Date.now() - request.start, "X-Request-ID": request.id, @@ -46,8 +48,14 @@ module.exports = function(request, response, result) { }; if (result.err) { - logging.error(request.id, result.err); - logging.error(request.id, result.err.stack); + var silent = silent_errors.indexOf(result.err.code) !== -1; + if (result.err.stack && !silent) { + logging.error(request.id, result.err.stack); + } else if (silent) { + logging.warn(request.id, result.err); + } else { + logging.error(request.id, result.err); + } result.status = -1; } diff --git a/lib/routes/avatars.js b/lib/routes/avatars.js index 0d03a22..f8e9076 100644 --- a/lib/routes/avatars.js +++ b/lib/routes/avatars.js @@ -1,4 +1,3 @@ -var logging = require("../logging"); var helpers = require("../helpers"); var config = require("../../config"); var skins = require("../skins"); @@ -82,7 +81,6 @@ module.exports = function(req, callback) { try { helpers.get_avatar(req.id, userId, helm, size, function(err, status, image, hash) { if (err) { - logging.error(req.id, err); if (err.code === "ENOENT") { // no such file cache.remove_hash(req.id, userId); @@ -101,7 +99,6 @@ module.exports = function(req, callback) { } }); } catch (e) { - logging.error(req.id, "error:", e.stack); handle_default(-1, userId, size, def, req, e, callback); } }; \ No newline at end of file diff --git a/lib/routes/capes.js b/lib/routes/capes.js index c3f303d..8cb302b 100644 --- a/lib/routes/capes.js +++ b/lib/routes/capes.js @@ -32,7 +32,6 @@ module.exports = function(req, callback) { try { helpers.get_cape(rid, userId, function(err, hash, status, image) { if (err) { - logging.error(rid, err); if (err.code === "ENOENT") { // no such file cache.remove_hash(rid, userId); diff --git a/lib/routes/renders.js b/lib/routes/renders.js index aa3288d..edef93b 100644 --- a/lib/routes/renders.js +++ b/lib/routes/renders.js @@ -98,7 +98,6 @@ module.exports = function(req, callback) { try { helpers.get_render(rid, userId, scale, helm, body, function(err, status, hash, image) { if (err) { - logging.error(rid, err); if (err.code === "ENOENT") { // no such file cache.remove_hash(rid, userId); @@ -118,7 +117,6 @@ module.exports = function(req, callback) { } }); } catch(e) { - logging.error(rid, "error:", e.stack); handle_default(rid, scale, helm, body, -1, userId, scale, def, req, e, callback); } }; \ No newline at end of file diff --git a/lib/routes/skins.js b/lib/routes/skins.js index b6173fb..8b926ac 100644 --- a/lib/routes/skins.js +++ b/lib/routes/skins.js @@ -81,7 +81,6 @@ module.exports = function(req, callback) { try { helpers.get_skin(rid, userId, function(err, hash, status, image) { if (err) { - logging.error(req.id, err); if (err.code === "ENOENT") { // no such file cache.remove_hash(req.id, userId); @@ -100,7 +99,6 @@ module.exports = function(req, callback) { } }); } catch(e) { - logging.error(rid, "error:", e.stack); handle_default(-1, userId, def, req, e, callback); } }; \ No newline at end of file diff --git a/lib/skins.js b/lib/skins.js index a302443..4599d80 100644 --- a/lib/skins.js +++ b/lib/skins.js @@ -126,7 +126,6 @@ exp.default_skin = function(uuid) { exp.open_skin = function(rid, skinpath, callback) { fs.readFile(skinpath, function(err, buf) { if (err) { - logging.error(rid, "error while opening skin file:", err); callback(err, null); } else { callback(null, buf);