Commit 9ec31214 authored by analog-nico's avatar analog-nico
Browse files

Untested implementation of custom unhandled rejection handling

parent 6e60d0b4
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
module.exports = require("bluebird/js/main/captured_trace")();

lib/bluebird-fresh.js

0 → 100644
+2 −0
Original line number Diff line number Diff line
// See: https://github.com/petkaantonov/bluebird#for-library-authors
module.exports = require("bluebird/js/main/promise")();
+9 −3
Original line number Diff line number Diff line
'use strict';

var Bluebird = require('bluebird'),
var Bluebird = require('./bluebird-fresh.js'),
    printRejectionReason = require('./bluebird-captured-trace-fresh.js').possiblyUnhandledRejection,
    _ = require('lodash');


Bluebird.onPossiblyUnhandledRejection(function (err) {
    // FIXME: Only ignore them if the user did not invoke 'then' yet.
Bluebird.onPossiblyUnhandledRejection(function (reason, promise) {
    if (promise._rp_then_invoked === true) {
        printRejectionReason(reason);
    }
    // else: The user did not call .then(...)
    // --> We need to assume that this request is processed with a callback or a pipe etc.
});


@@ -118,6 +123,7 @@ request.Request.prototype.init = function (options) {

request.Request.prototype.then = function (onFulfilled, onRejected) {
    this._rp_then_invoked = true;
    this._rp_promise._rp_then_invoked = true;
    return this._rp_promise.then(onFulfilled, onRejected);
};