From 6415c573fecb7c254f3b6869e46458e3651f9512 Mon Sep 17 00:00:00 2001 From: kangax Date: Thu, 8 Sep 2011 15:56:59 -0400 Subject: [PATCH] Intercept error in node requests to avoid process failing on connection refused or other errors. --- HEADER.js | 2 +- dist/all.js | 13 +++++++++++-- lib/fabric_node.js | 9 +++++++++ package.json | 2 +- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/HEADER.js b/HEADER.js index 4a86b150..71c06689 100644 --- a/HEADER.js +++ b/HEADER.js @@ -1,6 +1,6 @@ /*! Fabric.js Copyright 2008-2011, Bitsonnet (Juriy Zaytsev, Maxim Chernyak) */ -var fabric = fabric || { version: "0.5.9" }; +var fabric = fabric || { version: "0.5.10" }; if (typeof exports != 'undefined') { exports.fabric = fabric; diff --git a/dist/all.js b/dist/all.js index e735f868..81b41bbd 100644 --- a/dist/all.js +++ b/dist/all.js @@ -1,6 +1,6 @@ /*! Fabric.js Copyright 2008-2011, Bitsonnet (Juriy Zaytsev, Maxim Chernyak) */ -var fabric = fabric || { version: "0.5.9" }; +var fabric = fabric || { version: "0.5.10" }; if (typeof exports != 'undefined') { exports.fabric = fabric; @@ -10562,7 +10562,7 @@ fabric.util.object.extend(fabric.Canvas.prototype, { replacement.onload = function() { _this.setElement(replacement); callback && callback(); - replacement.onload = canvasEl = imgEl = null; + replacement.onload = canvasEl = imgEl = imageData = null; }; replacement.width = imgEl.width; replacement.height = imgEl.height; @@ -11127,6 +11127,15 @@ fabric.util.object.extend(fabric.Canvas.prototype, { client = HTTP.createClient(80, oURL.hostname), request = client.request('GET', oURL.pathname, { 'host': oURL.hostname }); + client.addListener('error', function(err) { + if (err.errno === process.ECONNREFUSED) { + fabric.log('ECONNREFUSED: connection refused to ' + client.host + ':' + client.port); + } + else { + fabric.log(err.message); + } + }); + request.end(); request.on('response', function (response) { var body = ""; diff --git a/lib/fabric_node.js b/lib/fabric_node.js index f7aad60b..3e5502a0 100644 --- a/lib/fabric_node.js +++ b/lib/fabric_node.js @@ -16,6 +16,15 @@ client = HTTP.createClient(80, oURL.hostname), request = client.request('GET', oURL.pathname, { 'host': oURL.hostname }); + client.addListener('error', function(err) { + if (err.errno === process.ECONNREFUSED) { + fabric.log('ECONNREFUSED: connection refused to ' + client.host + ':' + client.port); + } + else { + fabric.log(err.message); + } + }); + request.end(); request.on('response', function (response) { var body = ""; diff --git a/package.json b/package.json index 1aa91090..b159765d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "fabric", "description": "Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.", - "version": "0.5.9", + "version": "0.5.10", "author": "Juriy Zaytsev ", "keywords": ["canvas", "graphic", "graphics", "SVG", "node-canvas", "parser", "HTML5", "object model"], "repository": "git://github.com/kangax/fabric.js",