Comparing version 1.0.0 to 1.0.1
50
index.js
@@ -1,5 +0,10 @@ | ||
/*! | ||
/**! | ||
* sdk-base - index.js | ||
* Copyright(c) 2014 dead_horse <dead_horse@qq.com> | ||
* | ||
* Copyright(c) dead_horse and other contributors. | ||
* MIT Licensed | ||
* | ||
* Authors: | ||
* dead_horse <dead_horse@qq.com> | ||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com) | ||
*/ | ||
@@ -14,3 +19,3 @@ | ||
var EventEmitter = require('events').EventEmitter; | ||
var inherits = require('util').inherits; | ||
var util = require('util'); | ||
@@ -23,8 +28,12 @@ module.exports = Base; | ||
function Base () { | ||
function Base() { | ||
// defer bind default error handler | ||
var self = this; | ||
defer(function () { | ||
if (!self.listeners('error').length) self.on('error', onerror); | ||
}); | ||
if (!this.listeners('error').length) { | ||
/** | ||
* default error handler | ||
*/ | ||
this.on('error', this.defaultErrorHandler.bind(this)); | ||
} | ||
}.bind(this)); | ||
EventEmitter.call(this); | ||
@@ -37,10 +46,23 @@ } | ||
inherits(Base, EventEmitter); | ||
util.inherits(Base, EventEmitter); | ||
/** | ||
* default error handler | ||
*/ | ||
Base.prototype.defaultErrorHandler = function (err) { | ||
console.error('\n[%s][pid: %s][%s][%s] %s: %s \nError Stack:\n %s', | ||
Date(), process.pid, this.constructor.name, __filename, err.name, | ||
err.message, err.stack); | ||
function onerror(err) { | ||
if (process.env.NODE_ENV !== 'test') console.error(err.stack); | ||
} | ||
// try to show addition property on the error object | ||
// e.g.: `err.data = {url: '/foo'};` | ||
var additions = []; | ||
for (var key in err) { | ||
if (key === 'name' || key === 'message') { | ||
continue; | ||
} | ||
additions.push(util.format(' %s: %j', key, err[key])); | ||
} | ||
if (additions.length) { | ||
console.error('Error Additions:\n%s', additions.join('\n')); | ||
} | ||
console.error(); | ||
}; |
{ | ||
"name": "sdk-base", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "a base class for sdk with default error handler", | ||
@@ -9,3 +9,9 @@ "main": "index.js", | ||
}, | ||
"keywords": [], | ||
"keywords": [ | ||
"sdk", | ||
"error" | ||
], | ||
"files": [ | ||
"index.js" | ||
], | ||
"author": { | ||
@@ -21,5 +27,8 @@ "name": "dead_horse", | ||
"license": "MIT", | ||
"dependencies": {}, | ||
"dependencies": { | ||
}, | ||
"devDependencies": { | ||
"autod": "~0.3.2", | ||
"istanbul": "*", | ||
"mocha": "~1.21.4", | ||
@@ -26,0 +35,0 @@ "should": "~4.0.4" |
@@ -6,4 +6,7 @@ sdk-base | ||
[![build status][travis-image]][travis-url] | ||
[![Test coverage][coveralls-image]][coveralls-url] | ||
[![Gittip][gittip-image]][gittip-url] | ||
[![David deps][david-image]][david-url] | ||
[![node version][node-image]][node-url] | ||
[![Gittip][gittip-image]][gittip-url] | ||
[![npm download][download-image]][download-url] | ||
@@ -14,9 +17,16 @@ [npm-image]: https://img.shields.io/npm/v/sdk-base.svg?style=flat-square | ||
[travis-url]: https://travis-ci.org/node-modules/sdk-base | ||
[coveralls-image]: https://img.shields.io/coveralls/node-modules/sdk-base.svg?style=flat-square | ||
[coveralls-url]: https://coveralls.io/r/node-modules/sdk-base?branch=master | ||
[gittip-image]: https://img.shields.io/gittip/dead-horse.svg?style=flat-square | ||
[gittip-url]: https://www.gittip.com/dead-horse/ | ||
[david-image]: https://img.shields.io/david/node-modules/sdk-base.svg?style=flat-square | ||
[david-url]: https://david-dm.org/node-modules/sdk-base | ||
[node-image]: https://img.shields.io/badge/node.js-%3E=_0.8-green.svg?style=flat-square | ||
[node-url]: http://nodejs.org/download/ | ||
[gittip-image]: https://img.shields.io/gittip/dead-horse.svg?style=flat-square | ||
[gittip-url]: https://www.gittip.com/dead-horse/ | ||
[download-image]: https://img.shields.io/npm/dm/sdk-base.svg?style=flat-square | ||
[download-url]: https://npmjs.org/package/sdk-base | ||
a base class for sdk with default error handler. | ||
A base class for sdk with default error handler. | ||
## Installation | ||
@@ -39,3 +49,2 @@ | ||
util.inherits(Client, Base); | ||
``` | ||
@@ -42,0 +51,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
3652
54
52
0
4
3