master
Sven Slootweg 9 years ago
parent c2f7f1168f
commit 7e1f180cfd

@ -0,0 +1,52 @@
# bluebird-tap-error
Like `.tap` in Bluebird, but for errors. Sees errors, but doesn't catch them. Handy when you want to peek at errors, but want to do the actual error handling elsewhere.
[![](//img.shields.io/gratipay/joepie91.svg)](https://gratipay.com/joepie91)
## License
[WTFPL](http://www.wtfpl.net/txt/copying/) or [CC0](https://creativecommons.org/publicdomain/zero/1.0/), whichever you prefer. A donation and/or attribution are appreciated, but not required.
## Donate
My income consists entirely of donations for my projects. If this module is useful to you, consider [making a donation](http://cryto.net/~joepie91/donate.html)!
You can donate using Bitcoin, PayPal, Gratipay, Flattr, cash-in-mail, SEPA transfers, and pretty much anything else.
## Contributing
Pull requests welcome. Please make sure your modifications are in line with the overall code style, and ensure that you're editing the `.coffee` files, not the `.js` files.
Build tool of choice is `gulp`; simply run `gulp` while developing, and it will watch for changes.
Be aware that by making a pull request, you agree to release your modifications under the licenses stated above.
## Usage
A simple example:
```javascript
var Promise = require("bluebird");
var tapError = require("bluebird-tap-error");
Promise.try(function() {
return someBrokenAsyncThing();
}).catch(tapError(function(err) {
console.log("We saw an error!", err);
})).catch(function(err) {
/* The actual error handling goes here. */
})
```
## API
### tapError(func)
Wrap an error handling function in this function to make it tap into errors.
If an error occurred, it will be received by `func` (like it would happen for a normal `.catch`). The error is passed through as-is so that it can be handled elsewhere.
Any return value from this callback is ignored - including when the return value is a rejected Promise. You can *only* look at the error, and nothing else.
* __func__: The callback to use.

@ -0,0 +1,28 @@
var gulp = require('gulp');
/* CoffeeScript compile deps */
var path = require('path');
var gutil = require('gulp-util');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var coffee = require('gulp-coffee');
var cache = require('gulp-cached');
var remember = require('gulp-remember');
var plumber = require('gulp-plumber');
var source = ["lib/**/*.coffee", "index.coffee"]
gulp.task('coffee', function() {
return gulp.src(source, {base: "."})
.pipe(plumber())
.pipe(cache("coffee"))
.pipe(coffee({bare: true}).on('error', gutil.log)).on('data', gutil.log)
.pipe(remember("coffee"))
.pipe(gulp.dest("."));
});
gulp.task('watch', function () {
gulp.watch(source, ['coffee']);
});
gulp.task('default', ['coffee', 'watch']);

@ -0,0 +1 @@
module.exports = require "./lib"

@ -0,0 +1 @@
module.exports = require("./lib");

@ -0,0 +1,11 @@
Promise = require "bluebird"
module.exports = (func) ->
return (err) ->
Promise.try ->
func(err)
.catch ->
# Consume any errors
Promise.resolve()
.then ->
Promise.reject(err)

@ -0,0 +1,15 @@
var Promise;
Promise = require("bluebird");
module.exports = function(func) {
return function(err) {
return Promise["try"](function() {
return func(err);
})["catch"](function() {
return Promise.resolve();
}).then(function() {
return Promise.reject(err);
});
};
};

@ -0,0 +1,36 @@
{
"name": "bluebird-tap-error",
"version": "1.0.0",
"description": "Like .tap, but for errors (rejections)",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git@git.cryto.net:projects/joepie91/node-bluebird-tap-error"
},
"keywords": [
"bluebird",
"promises",
"errors",
"tap"
],
"author": "Sven Slootweg",
"license": "WTFPL",
"dependencies": {
"bluebird": "^2.9.24"
},
"devDependencies": {
"gulp": "~3.8.0",
"gulp-cached": "~0.0.3",
"gulp-coffee": "~2.0.1",
"gulp-concat": "~2.2.0",
"gulp-livereload": "~2.1.0",
"gulp-nodemon": "~1.0.4",
"gulp-plumber": "~0.6.3",
"gulp-remember": "~0.2.0",
"gulp-rename": "~1.2.0",
"gulp-util": "~2.2.17"
}
}
Loading…
Cancel
Save