safe-errors
Advanced tools
Comparing version 0.0.3 to 0.2.0
'use strict'; | ||
const Promise = require('bluebird'); | ||
var Promise = require('bluebird'); | ||
function safecb(fn, ctx) { | ||
return function () { | ||
let args = [].slice.call(arguments); | ||
return new Promise(resolve => { | ||
let done = function () { | ||
let doneArgs = [].slice.call(arguments); | ||
let error = doneArgs.shift(); | ||
var args = [].slice.call(arguments); | ||
return new Promise(function (resolve) { | ||
var done = function done() { | ||
var doneArgs = [].slice.call(arguments); | ||
var error = doneArgs.shift(); | ||
@@ -16,3 +16,3 @@ if (error) { | ||
success: false, | ||
error | ||
error: error | ||
}); | ||
@@ -31,6 +31,6 @@ return; | ||
fn.apply(ctx, args); | ||
}).catch(error => { | ||
}).catch(function (error) { | ||
return { | ||
success: false, | ||
error | ||
error: error | ||
}; | ||
@@ -42,3 +42,3 @@ }); | ||
module.exports = { | ||
safecb | ||
safecb: safecb | ||
}; |
'use strict'; | ||
const { safecb } = require('./safecb'); | ||
const deep = require('assert').deepEqual; | ||
var _require = require('./safecb'); | ||
describe('safe callback', () => { | ||
it('should convert a callback to a promise', () => { | ||
let cb = (a, b, done) => { | ||
var safecb = _require.safecb; | ||
var deep = require('assert').deepEqual; | ||
describe('safe callback', function () { | ||
it('should convert a callback to a promise', function () { | ||
var cb = function cb(a, b, done) { | ||
done(null, '1'); | ||
}; | ||
return safecb(cb)('a', 'b').then(result => { | ||
return safecb(cb)('a', 'b').then(function (result) { | ||
deep(result.success, true); | ||
@@ -19,8 +22,8 @@ deep(result.payload, '1'); | ||
it('should convert a callback to a promise and handle no arguments', () => { | ||
let cb = done => { | ||
it('should convert a callback to a promise and handle no arguments', function () { | ||
var cb = function cb(done) { | ||
done(null, 'a'); | ||
}; | ||
return safecb(cb)().then(result => { | ||
return safecb(cb)().then(function (result) { | ||
deep(result.success, true); | ||
@@ -31,9 +34,9 @@ deep(result.payload[0], 'a'); | ||
it('should convert a callback to a promise and handle errors', () => { | ||
let error = new Error('error in cb'); | ||
let cb = (a, b, done) => { | ||
it('should convert a callback to a promise and handle errors', function () { | ||
var error = new Error('error in cb'); | ||
var cb = function cb(a, b, done) { | ||
done(error); | ||
}; | ||
return safecb(cb)('a', 'b').then(result => { | ||
return safecb(cb)('a', 'b').then(function (result) { | ||
deep(result.success, false); | ||
@@ -44,10 +47,10 @@ deep(result.error, error); | ||
it('should convert a callback to a promise and catch errors', () => { | ||
let error = new Error('error thrown in cb'); | ||
it('should convert a callback to a promise and catch errors', function () { | ||
var error = new Error('error thrown in cb'); | ||
let cb = (a, b, done) => { | ||
var cb = function cb(a, b, done) { | ||
throw error; | ||
}; | ||
return safecb(cb)('a', 'b').then(result => { | ||
return safecb(cb)('a', 'b').then(function (result) { | ||
deep(result.success, false); | ||
@@ -54,0 +57,0 @@ deep(result.error, error); |
@@ -5,11 +5,11 @@ "use strict"; | ||
return function () { | ||
return p.apply(ctx, arguments).then(payload => { | ||
return p.apply(ctx, arguments).then(function (payload) { | ||
return { | ||
success: true, | ||
payload | ||
payload: payload | ||
}; | ||
}).catch(error => { | ||
}).catch(function (error) { | ||
return { | ||
success: false, | ||
error | ||
error: error | ||
}; | ||
@@ -21,3 +21,3 @@ }); | ||
module.exports = { | ||
safep | ||
safep: safep | ||
}; |
'use strict'; | ||
const { safep } = require('./safep'); | ||
const deep = require('assert').deepEqual; | ||
var _require = require('./safep'); | ||
describe('safe promise', () => { | ||
it('should convert a promise to a safe promise', () => { | ||
let p = () => { | ||
var safep = _require.safep; | ||
var deep = require('assert').deepEqual; | ||
describe('safe promise', function () { | ||
it('should convert a promise to a safe promise', function () { | ||
var p = function p() { | ||
return Promise.resolve('a'); | ||
}; | ||
return safep(p)().then(result => { | ||
return safep(p)().then(function (result) { | ||
deep(result.success, true); | ||
@@ -18,9 +21,9 @@ deep(result.payload, 'a'); | ||
it('should return reject promise result', () => { | ||
let error = new Error('something bad!'); | ||
let p = () => { | ||
it('should return reject promise result', function () { | ||
var error = new Error('something bad!'); | ||
var p = function p() { | ||
return Promise.reject(error); | ||
}; | ||
return safep(p)().then(result => { | ||
return safep(p)().then(function (result) { | ||
deep(result.success, false); | ||
@@ -27,0 +30,0 @@ deep(result.error, error); |
{ | ||
"name": "safe-errors", | ||
"version": "0.0.3", | ||
"version": "0.2.0", | ||
"description": "", | ||
@@ -14,2 +14,5 @@ "main": "index.js", | ||
"bluebird": "^3.4.6", | ||
"babel-core": "^6.14.0", | ||
"babel-preset-es2015": "^6.14.0", | ||
"body-parser": "^1.15.2", | ||
"mocha": "^3.0.2" | ||
@@ -16,0 +19,0 @@ }, |
@@ -65,3 +65,3 @@ # Safe Errors | ||
if (result.success === false) { | ||
log(result.error) | ||
log(result.success === false) | ||
// maybe return a default | ||
@@ -68,0 +68,0 @@ return {} |
Sorry, the diff of this file is not supported yet
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
10003
247
5
+ Addedbabel-core@^6.14.0
+ Addedbabel-preset-es2015@^6.14.0
+ Addedbody-parser@^1.15.2
+ Addedansi-regex@2.1.1(transitive)
+ Addedansi-styles@2.2.1(transitive)
+ Addedbabel-code-frame@6.26.0(transitive)
+ Addedbabel-core@6.26.3(transitive)
+ Addedbabel-generator@6.26.1(transitive)
+ Addedbabel-helper-call-delegate@6.24.1(transitive)
+ Addedbabel-helper-define-map@6.26.0(transitive)
+ Addedbabel-helper-function-name@6.24.1(transitive)
+ Addedbabel-helper-get-function-arity@6.24.1(transitive)
+ Addedbabel-helper-hoist-variables@6.24.1(transitive)
+ Addedbabel-helper-optimise-call-expression@6.24.1(transitive)
+ Addedbabel-helper-regex@6.26.0(transitive)
+ Addedbabel-helper-replace-supers@6.24.1(transitive)
+ Addedbabel-helpers@6.24.1(transitive)
+ Addedbabel-messages@6.23.0(transitive)
+ Addedbabel-plugin-check-es2015-constants@6.22.0(transitive)
+ Addedbabel-plugin-transform-es2015-arrow-functions@6.22.0(transitive)
+ Addedbabel-plugin-transform-es2015-block-scoped-functions@6.22.0(transitive)
+ Addedbabel-plugin-transform-es2015-block-scoping@6.26.0(transitive)
+ Addedbabel-plugin-transform-es2015-classes@6.24.1(transitive)
+ Addedbabel-plugin-transform-es2015-computed-properties@6.24.1(transitive)
+ Addedbabel-plugin-transform-es2015-destructuring@6.23.0(transitive)
+ Addedbabel-plugin-transform-es2015-duplicate-keys@6.24.1(transitive)
+ Addedbabel-plugin-transform-es2015-for-of@6.23.0(transitive)
+ Addedbabel-plugin-transform-es2015-function-name@6.24.1(transitive)
+ Addedbabel-plugin-transform-es2015-literals@6.22.0(transitive)
+ Addedbabel-plugin-transform-es2015-modules-amd@6.24.1(transitive)
+ Addedbabel-plugin-transform-es2015-modules-commonjs@6.26.2(transitive)
+ Addedbabel-plugin-transform-es2015-modules-systemjs@6.24.1(transitive)
+ Addedbabel-plugin-transform-es2015-modules-umd@6.24.1(transitive)
+ Addedbabel-plugin-transform-es2015-object-super@6.24.1(transitive)
+ Addedbabel-plugin-transform-es2015-parameters@6.24.1(transitive)
+ Addedbabel-plugin-transform-es2015-shorthand-properties@6.24.1(transitive)
+ Addedbabel-plugin-transform-es2015-spread@6.22.0(transitive)
+ Addedbabel-plugin-transform-es2015-sticky-regex@6.24.1(transitive)
+ Addedbabel-plugin-transform-es2015-template-literals@6.22.0(transitive)
+ Addedbabel-plugin-transform-es2015-typeof-symbol@6.23.0(transitive)
+ Addedbabel-plugin-transform-es2015-unicode-regex@6.24.1(transitive)
+ Addedbabel-plugin-transform-regenerator@6.26.0(transitive)
+ Addedbabel-plugin-transform-strict-mode@6.24.1(transitive)
+ Addedbabel-preset-es2015@6.24.1(transitive)
+ Addedbabel-register@6.26.0(transitive)
+ Addedbabel-runtime@6.26.0(transitive)
+ Addedbabel-template@6.26.0(transitive)
+ Addedbabel-traverse@6.26.0(transitive)
+ Addedbabel-types@6.26.0(transitive)
+ Addedbabylon@6.18.0(transitive)
+ Addedbody-parser@1.20.3(transitive)
+ Addedbytes@3.1.2(transitive)
+ Addedcall-bind@1.0.7(transitive)
+ Addedchalk@1.1.3(transitive)
+ Addedcontent-type@1.0.5(transitive)
+ Addedconvert-source-map@1.9.0(transitive)
+ Addedcore-js@2.6.12(transitive)
+ Addeddebug@2.6.9(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addeddepd@2.0.0(transitive)
+ Addeddestroy@1.2.0(transitive)
+ Addeddetect-indent@4.0.0(transitive)
+ Addedee-first@1.1.1(transitive)
+ Addedes-define-property@1.0.0(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedesutils@2.0.3(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.2.4(transitive)
+ Addedglobals@9.18.0(transitive)
+ Addedgopd@1.0.1(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-proto@1.0.3(transitive)
+ Addedhas-symbols@1.0.3(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhome-or-tmp@2.0.0(transitive)
+ Addedhttp-errors@2.0.0(transitive)
+ Addediconv-lite@0.4.24(transitive)
+ Addedinvariant@2.2.4(transitive)
+ Addedis-finite@1.1.0(transitive)
+ Addedjs-tokens@3.0.2(transitive)
+ Addedjsesc@0.5.01.3.0(transitive)
+ Addedjson5@0.5.1(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedloose-envify@1.4.0(transitive)
+ Addedmedia-typer@0.3.0(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedmkdirp@0.5.6(transitive)
+ Addedobject-inspect@1.13.2(transitive)
+ Addedon-finished@2.4.1(transitive)
+ Addedos-homedir@1.0.2(transitive)
+ Addedos-tmpdir@1.0.2(transitive)
+ Addedprivate@0.1.8(transitive)
+ Addedqs@6.13.0(transitive)
+ Addedraw-body@2.5.2(transitive)
+ Addedregenerate@1.4.2(transitive)
+ Addedregenerator-runtime@0.11.1(transitive)
+ Addedregenerator-transform@0.10.1(transitive)
+ Addedregexpu-core@2.0.0(transitive)
+ Addedregjsgen@0.2.0(transitive)
+ Addedregjsparser@0.1.5(transitive)
+ Addedrepeating@2.0.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedsetprototypeof@1.2.0(transitive)
+ Addedside-channel@1.0.6(transitive)
+ Addedslash@1.0.0(transitive)
+ Addedsource-map@0.5.7(transitive)
+ Addedsource-map-support@0.4.18(transitive)
+ Addedstatuses@2.0.1(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedsupports-color@2.0.0(transitive)
+ Addedto-fast-properties@1.0.3(transitive)
+ Addedtoidentifier@1.0.1(transitive)
+ Addedtrim-right@1.0.1(transitive)
+ Addedtype-is@1.6.18(transitive)
+ Addedunpipe@1.0.0(transitive)