[Pkg-javascript-commits] [node-errorhandler] 02/07: Imported Upstream version 1.2.0
Leo Iannacone
l3on-guest at moszumanska.debian.org
Sat Oct 11 16:48:41 UTC 2014
This is an automated email from the git hooks/post-receive script.
l3on-guest pushed a commit to branch master
in repository node-errorhandler.
commit 208a9989a2b89d0724b5554802ba67da6f63b384
Author: Leo Iannacone <l3on at ubuntu.com>
Date: Sat Oct 11 18:35:05 2014 +0200
Imported Upstream version 1.2.0
---
.npmignore | 3 ---
History.md => HISTORY.md | 6 ++++++
LICENSE | 22 +++++++++++++++++++++
README.md | 50 +++++++++++++++++++++++-------------------------
index.js | 36 ++++++++++++++++++++++++++++++----
package.json | 27 +++++++++++++++++---------
test/test.js | 15 +++++++++++++--
7 files changed, 115 insertions(+), 44 deletions(-)
diff --git a/.npmignore b/.npmignore
deleted file mode 100644
index cd39b77..0000000
--- a/.npmignore
+++ /dev/null
@@ -1,3 +0,0 @@
-coverage/
-test/
-.travis.yml
diff --git a/History.md b/HISTORY.md
similarity index 83%
rename from History.md
rename to HISTORY.md
index 44a060a..888125c 100644
--- a/History.md
+++ b/HISTORY.md
@@ -1,3 +1,9 @@
+1.2.0 / 2014-09-02
+==================
+
+ * Display error using `util.inspect` if no other representation
+ * deps: accepts@~1.1.0
+
1.1.1 / 2014-06-20
==================
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..f23dca8
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,22 @@
+(The MIT License)
+
+Copyright (c) 2014 Jonathan Ong <me at jongleberry.com>
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/README.md b/README.md
index ca10d41..194d024 100644
--- a/README.md
+++ b/README.md
@@ -1,10 +1,12 @@
# errorhandler
-[![NPM version](https://badge.fury.io/js/errorhandler.svg)](http://badge.fury.io/js/errorhandler)
-[![Build Status](https://travis-ci.org/expressjs/errorhandler.svg?branch=master)](https://travis-ci.org/expressjs/errorhandler)
-[![Coverage Status](https://img.shields.io/coveralls/expressjs/errorhandler.svg?branch=master)](https://coveralls.io/r/expressjs/errorhandler)
+[![NPM Version][npm-image]][npm-url]
+[![NPM Downloads][downloads-image]][downloads-url]
+[![Build Status][travis-image]][travis-url]
+[![Test Coverage][coveralls-image]][coveralls-url]
+[![Gratipay][gratipay-image]][gratipay-url]
-Previously `connect.errorHandler()`.
+Development-only error handler middleware
## Install
@@ -14,11 +16,15 @@ $ npm install errorhandler
## API
+```js
+var errorhandler = require('errorhandler')
+```
+
### errorhandler()
Create new middleware to handle errors and respond with content negotiation.
This middleware is only intended to be used in a development environment, as
-the full error stack traces will be send back to the client when an error
+the full error stack traces will be sent back to the client when an error
occurs.
## Example
@@ -30,30 +36,22 @@ var errorhandler = require('errorhandler')
var app = connect()
if (process.env.NODE_ENV === 'development') {
+ // only use in development
app.use(errorhandler())
}
```
## License
-The MIT License (MIT)
-
-Copyright (c) 2014 Jonathan Ong me at jongleberry.com
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
+[MIT](LICENSE)
+
+[npm-image]: https://img.shields.io/npm/v/errorhandler.svg?style=flat
+[npm-url]: https://npmjs.org/package/errorhandler
+[travis-image]: https://img.shields.io/travis/expressjs/errorhandler.svg?style=flat
+[travis-url]: https://travis-ci.org/expressjs/errorhandler
+[coveralls-image]: https://img.shields.io/coveralls/expressjs/errorhandler.svg?style=flat
+[coveralls-url]: https://coveralls.io/r/expressjs/errorhandler?branch=master
+[downloads-image]: http://img.shields.io/npm/dm/errorhandler.svg?style=flat
+[downloads-url]: https://npmjs.org/package/errorhandler
+[gratipay-image]: https://img.shields.io/gratipay/dougwilson.svg?style=flat
+[gratipay-url]: https://www.gratipay.com/dougwilson/
diff --git a/index.js b/index.js
index 16e044f..e4ea469 100644
--- a/index.js
+++ b/index.js
@@ -2,6 +2,7 @@
* errorhandler
* Copyright(c) 2010 Sencha Inc.
* Copyright(c) 2011 TJ Holowaychuk
+ * Copyright(c) 2014 Jonathan Ong
* MIT Licensed
*/
@@ -12,6 +13,14 @@
var accepts = require('accepts')
var escapeHtml = require('escape-html');
var fs = require('fs');
+var util = require('util')
+
+/**
+ * Module variables.
+ */
+
+var inspect = util.inspect
+var toString = Object.prototype.toString
/**
* Error handler:
@@ -55,7 +64,7 @@ exports = module.exports = function errorHandler(){
// write error to console
if (env !== 'test') {
- console.error(err.stack || String(err))
+ console.error(stringify(err))
}
// cannot actually respond
@@ -76,7 +85,7 @@ exports = module.exports = function errorHandler(){
if (e) return next(e);
fs.readFile(__dirname + '/public/error.html', 'utf8', function(e, html){
if (e) return next(e);
- var stack = (err.stack || '')
+ var stack = String(err.stack || '')
.split('\n').slice(1)
.map(function(v){ return '<li>' + escapeHtml(v).replace(/ /g, ' ') + '</li>'; }).join('');
html = html
@@ -84,7 +93,7 @@ exports = module.exports = function errorHandler(){
.replace('{stack}', stack)
.replace('{title}', escapeHtml(exports.title))
.replace('{statusCode}', res.statusCode)
- .replace(/\{error\}/g, escapeHtml(String(err)).replace(/ /g, ' ').replace(/\n/g, '<br>'));
+ .replace(/\{error\}/g, escapeHtml(stringify(err)).replace(/ /g, ' ').replace(/\n/g, '<br>'));
res.setHeader('Content-Type', 'text/html; charset=utf-8');
res.end(html);
});
@@ -99,7 +108,7 @@ exports = module.exports = function errorHandler(){
// plain text
} else {
res.setHeader('Content-Type', 'text/plain');
- res.end(err.stack || String(err));
+ res.end(stringify(err));
}
};
};
@@ -109,3 +118,22 @@ exports = module.exports = function errorHandler(){
*/
exports.title = 'Connect';
+
+/**
+ * Stringify a value.
+ * @api private
+ */
+
+function stringify(val) {
+ var stack = val.stack
+
+ if (stack) {
+ return String(stack)
+ }
+
+ var str = String(val)
+
+ return str === toString.call(val)
+ ? inspect(val)
+ : str
+}
diff --git a/package.json b/package.json
index 01d7098..5c1210f 100644
--- a/package.json
+++ b/package.json
@@ -1,27 +1,36 @@
{
"name": "errorhandler",
- "description": "connect's default error handler page",
- "version": "1.1.1",
- "author": "Jonathan Ong <me at jongleberry.com> (http://jongleberry.com)",
+ "description": "Development-only error handler middleware",
+ "version": "1.2.0",
+ "contributors": [
+ "Douglas Christopher Wilson <doug at somethingdoug.com>",
+ "Jonathan Ong <me at jongleberry.com> (http://jongleberry.com)"
+ ],
"license": "MIT",
"repository": "expressjs/errorhandler",
"dependencies": {
- "accepts": "~1.0.4",
+ "accepts": "~1.1.0",
"escape-html": "1.0.1"
},
"devDependencies": {
"connect": "3",
- "istanbul": "0.2.10",
- "mocha": "~1.20.1",
+ "istanbul": "0.3.0",
+ "mocha": "~1.21.4",
"should": "~4.0.1",
"supertest": "~0.13.0"
},
+ "files": [
+ "public/",
+ "LICENSE",
+ "HISTORY.md",
+ "index.js"
+ ],
"engines": {
"node": ">= 0.8"
},
"scripts": {
- "test": "mocha --reporter dot test/",
- "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot test/",
- "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec test/"
+ "test": "mocha --reporter spec --bail --check-leaks test/",
+ "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",
+ "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/"
}
}
diff --git a/test/test.js b/test/test.js
index 083bc95..f9a16df 100644
--- a/test/test.js
+++ b/test/test.js
@@ -175,12 +175,23 @@ describe('errorHandler()', function () {
})
it('should stringify plain object', function (done) {
- error = {}
+ error = {hop: 'pop'}
request(app)
.get('/')
.expect(500, function (err) {
if (err) return done(err)
- log.should.equal('[object Object]')
+ log.should.equal('{ hop: \'pop\' }')
+ done()
+ })
+ })
+
+ it('should stringify number', function (done) {
+ error = 42
+ request(app)
+ .get('/')
+ .expect(500, function (err) {
+ if (err) return done(err)
+ log.should.equal('42')
done()
})
})
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-errorhandler.git
More information about the Pkg-javascript-commits
mailing list