# add dist

This commit is contained in:
Mario Romano
2016-04-21 11:56:31 +01:00
parent 5914688467
commit 07807e7bc3
13499 changed files with 1808930 additions and 5 deletions

View File

@@ -0,0 +1,76 @@
2015-02-02 / 1.3.1
==================
* Fix regression where status can be overwritten in `createError` `props`
2015-02-01 / 1.3.0
==================
* Construct errors using defined constructors from `createError`
* Fix error names that are not identifiers
- `createError["I'mateapot"]` is now `createError.ImATeapot`
* Set a meaningful `name` property on constructed errors
2014-12-09 / 1.2.8
==================
* Fix stack trace from exported function
* Remove `arguments.callee` usage
2014-10-14 / 1.2.7
==================
* Remove duplicate line
2014-10-02 / 1.2.6
==================
* Fix `expose` to be `true` for `ClientError` constructor
2014-09-28 / 1.2.5
==================
* deps: statuses@1
2014-09-21 / 1.2.4
==================
* Fix dependency version to work with old `npm`s
2014-09-21 / 1.2.3
==================
* deps: statuses@~1.1.0
2014-09-21 / 1.2.2
==================
* Fix publish error
2014-09-21 / 1.2.1
==================
* Support Node.js 0.6
* Use `inherits` instead of `util`
2014-09-09 / 1.2.0
==================
* Fix the way inheriting functions
* Support `expose` being provided in properties argument
2014-09-08 / 1.1.0
==================
* Default status to 500
* Support provided `error` to extend
2014-09-08 / 1.0.1
==================
* Fix accepting string message
2014-09-08 / 1.0.0
==================
* Initial release

View File

@@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2014 Jonathan Ong me@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.

View File

@@ -0,0 +1,63 @@
# http-errors
[![NPM Version][npm-image]][npm-url]
[![NPM Downloads][downloads-image]][downloads-url]
[![Node.js Version][node-version-image]][node-version-url]
[![Build Status][travis-image]][travis-url]
[![Test Coverage][coveralls-image]][coveralls-url]
Create HTTP errors for Express, Koa, Connect, etc. with ease.
## Example
```js
var createError = require('http-errors');
app.use(function (req, res, next) {
if (!req.user) return next(createError(401, 'Please login to view this page.'));
next();
})
```
## API
This is the current API, currently extracted from Koa and subject to change.
### Error Properties
- `message`
- `status` and `statusCode` - the status code of the error, defaulting to `500`
### createError([status], [message], [properties])
```js
var err = createError(404, 'This video does not exist!');
```
- `status: 500` - the status code as a number
- `message` - the message of the error, defaulting to node's text for that status code.
- `properties` - custom properties to attach to the object
### new createError\[code || name\](\[msg]\))
```js
var err = new createError.NotFound();
```
- `code` - the status code as a number
- `name` - the name of the error as a "bumpy case", i.e. `NotFound` or `InternalServerError`.
## License
[MIT](LICENSE)
[npm-image]: https://img.shields.io/npm/v/http-errors.svg?style=flat
[npm-url]: https://npmjs.org/package/http-errors
[node-version-image]: https://img.shields.io/node/v/http-errors.svg?style=flat
[node-version-url]: http://nodejs.org/download/
[travis-image]: https://img.shields.io/travis/jshttp/http-errors.svg?style=flat
[travis-url]: https://travis-ci.org/jshttp/http-errors
[coveralls-image]: https://img.shields.io/coveralls/jshttp/http-errors.svg?style=flat
[coveralls-url]: https://coveralls.io/r/jshttp/http-errors
[downloads-image]: https://img.shields.io/npm/dm/http-errors.svg?style=flat
[downloads-url]: https://npmjs.org/package/http-errors

View File

@@ -0,0 +1,120 @@
var statuses = require('statuses');
var inherits = require('inherits');
function toIdentifier(str) {
return str.split(' ').map(function (token) {
return token.slice(0, 1).toUpperCase() + token.slice(1)
}).join('').replace(/[^ _0-9a-z]/gi, '')
}
exports = module.exports = function httpError() {
// so much arity going on ~_~
var err;
var msg;
var status = 500;
var props = {};
for (var i = 0; i < arguments.length; i++) {
var arg = arguments[i];
if (arg instanceof Error) {
err = arg;
status = err.status || err.statusCode || status;
continue;
}
switch (typeof arg) {
case 'string':
msg = arg;
break;
case 'number':
status = arg;
break;
case 'object':
props = arg;
break;
}
}
if (typeof status !== 'number' || !statuses[status]) {
status = 500
}
// constructor
var HttpError = exports[status]
if (!err) {
// create error
err = HttpError
? new HttpError(msg)
: new Error(msg || statuses[status])
Error.captureStackTrace(err, httpError)
}
if (!HttpError || !(err instanceof HttpError)) {
// add properties to generic error
err.expose = status < 500
err.status = err.statusCode = status
}
for (var key in props) {
if (key !== 'status' && key !== 'statusCode') {
err[key] = props[key]
}
}
return err;
};
// create generic error objects
var codes = statuses.codes.filter(function (num) {
return num >= 400;
});
codes.forEach(function (code) {
var name = toIdentifier(statuses[code])
var className = name.match(/Error$/) ? name : name + 'Error'
if (code >= 500) {
var ServerError = function ServerError(msg) {
var self = new Error(msg != null ? msg : statuses[code])
Error.captureStackTrace(self, ServerError)
self.__proto__ = ServerError.prototype
Object.defineProperty(self, 'name', {
enumerable: false,
configurable: true,
value: className,
writable: true
})
return self
}
inherits(ServerError, Error);
ServerError.prototype.status =
ServerError.prototype.statusCode = code;
ServerError.prototype.expose = false;
exports[code] =
exports[name] = ServerError
return;
}
var ClientError = function ClientError(msg) {
var self = new Error(msg != null ? msg : statuses[code])
Error.captureStackTrace(self, ClientError)
self.__proto__ = ClientError.prototype
Object.defineProperty(self, 'name', {
enumerable: false,
configurable: true,
value: className,
writable: true
})
return self
}
inherits(ClientError, Error);
ClientError.prototype.status =
ClientError.prototype.statusCode = code;
ClientError.prototype.expose = true;
exports[code] =
exports[name] = ClientError
return;
});
// backwards-compatibility
exports["I'mateapot"] = exports.ImATeapot

View File

@@ -0,0 +1,112 @@
{
"_args": [
[
"http-errors@~1.3.1",
"/Users/mromano/dev/dev-platform-webcomponents/ng2-components/ng2-alfresco-documentslist/node_modules/serve-index"
]
],
"_from": "http-errors@>=1.3.1 <1.4.0",
"_id": "http-errors@1.3.1",
"_inCache": true,
"_installable": true,
"_location": "/http-errors",
"_npmUser": {
"email": "doug@somethingdoug.com",
"name": "dougwilson"
},
"_npmVersion": "1.4.28",
"_phantomChildren": {},
"_requested": {
"name": "http-errors",
"raw": "http-errors@~1.3.1",
"rawSpec": "~1.3.1",
"scope": null,
"spec": ">=1.3.1 <1.4.0",
"type": "range"
},
"_requiredBy": [
"/live-server/send",
"/serve-index",
"/serve-static/send"
],
"_resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.3.1.tgz",
"_shasum": "197e22cdebd4198585e8694ef6786197b91ed942",
"_shrinkwrap": null,
"_spec": "http-errors@~1.3.1",
"_where": "/Users/mromano/dev/dev-platform-webcomponents/ng2-components/ng2-alfresco-documentslist/node_modules/serve-index",
"author": {
"email": "me@jongleberry.com",
"name": "Jonathan Ong",
"url": "http://jongleberry.com"
},
"bugs": {
"url": "https://github.com/jshttp/http-errors/issues"
},
"contributors": [
{
"email": "me@pluma.io",
"name": "Alan Plum"
},
{
"email": "doug@somethingdoug.com",
"name": "Douglas Christopher Wilson"
}
],
"dependencies": {
"inherits": "~2.0.1",
"statuses": "1"
},
"description": "Create HTTP error objects",
"devDependencies": {
"istanbul": "0",
"mocha": "1"
},
"directories": {},
"dist": {
"shasum": "197e22cdebd4198585e8694ef6786197b91ed942",
"tarball": "https://registry.npmjs.org/http-errors/-/http-errors-1.3.1.tgz"
},
"engines": {
"node": ">= 0.6"
},
"files": [
"index.js",
"HISTORY.md",
"LICENSE",
"README.md"
],
"gitHead": "89a8502b40d5dd42da2908f265275e2eeb8d0699",
"homepage": "https://github.com/jshttp/http-errors",
"keywords": [
"http",
"error"
],
"license": "MIT",
"maintainers": [
{
"email": "npm@egeste.net",
"name": "egeste"
},
{
"email": "jonathanrichardong@gmail.com",
"name": "jongleberry"
},
{
"email": "doug@somethingdoug.com",
"name": "dougwilson"
}
],
"name": "http-errors",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git+https://github.com/jshttp/http-errors.git"
},
"scripts": {
"test": "mocha --reporter spec --bail",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot",
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter dot"
},
"version": "1.3.1"
}