How to use the reject function from bluebird

Find comprehensive JavaScript bluebird.reject code examples handpicked from public code repositorys.

bluebird.reject creates a new promise that is rejected with a given reason.

704
705
706
707
708
709
710
711
712
describe("on fail", () => {
    it("should extend error with hermioneCtx object passed to execution thread", async () => {
        ExecutionThread.create.callsFake(({ hermioneCtx }) => {
            ExecutionThread.prototype.run.callsFake(() => {
                hermioneCtx.foo = "bar";
                return Promise.reject(new Error());
            });
            return Object.create(ExecutionThread.prototype);
        });
fork icon56
star icon555
watch icon11

+ 63 other calls in file

47
48
49
50
51
52
53
54
55
56
    this.log(`has cached browser ${browser.fullId}`);

    return browser
        .reset()
        .catch(e => {
            const reject = Promise.reject.bind(null, e);
            return this.underlyingPool.freeBrowser(browser).then(reject, reject);
        })
        .then(() => browser);
}
fork icon56
star icon555
watch icon11

+ 15 other calls in file

How does bluebird.reject work?

bluebird.reject is a method provided by the Bluebird library that returns a rejected promise with the specified error or reason. When you call bluebird.reject with an error or reason, it immediately creates a new promise object that is rejected with that error or reason. This is useful for creating a promise that is immediately rejected, without needing to wait for any asynchronous work to complete. The rejected promise can then be used in a catch block to handle the error or reason that caused the rejection.

262
263
264
265
266
267
268
269
270
271
    .withArgs("first")
    .returns(Promise.resolve(stubBrowser()))
    .withArgs("second")
    .returns(Promise.resolve(expectedBrowser));

underlyingPool.freeBrowser.callsFake(() => Promise.reject());

return pool
    .getBrowser("first")
    .then(browser => {
fork icon56
star icon555
watch icon11

+ 31 other calls in file

26
27
28
29
30
31
32
33
34

            if (injectAllowed) {
                return this._inject().then(() => this._callCommand(command, false));
            }

            return Promise.reject(new ClientBridgeError("Unable to inject client script"));
        })
        .catch(e => Promise.reject(new ClientBridgeError(e.message)));
}
fork icon56
star icon555
watch icon11

+ 23 other calls in file

Ai Example

1
2
3
4
5
const Promise = require("bluebird");

const someError = new Error("Something went wrong");

Promise.reject(someError).catch((error) => console.error(error));

In this example, Promise.reject is used to create a rejected promise with an Error object as the rejection reason. The rejection is then caught and the error message is logged to the console using console.error.

742
743
744
745
746
747
748
749
750
751
const assertViewResults = AssertViewResults.create([new Error()]);

ExecutionThread.create.callsFake(({hermioneCtx}) => {
    ExecutionThread.prototype.run.callsFake(() => {
        hermioneCtx.assertViewResults = assertViewResults;
        return Promise.reject(new Error('runtime error'));
    });

    return Object.create(ExecutionThread.prototype);
});
fork icon56
star icon555
watch icon11

+ 3 other calls in file

63
64
65
66
67
68
69
70
71
72
  }

  return gitCmds
    .safeUnstashAll()
    .then(function() {
      return Promise.reject(e);
    });
})
.then(function() {
  console.log(
fork icon31
star icon365
watch icon17

+ 3 other calls in file

386
387
388
389
390
391
392
393
394
395
396
		});
};


const createUserOrderByNetworkId = (networkId, symbol, side, size, type, price = 0, opts = { stop: null, meta: null, additionalHeaders: null }) => {
	if (!networkId) {
		return reject(new Error(USER_NOT_REGISTERED_ON_NETWORK));
	}
	if (symbol && !subscribedToPair(symbol)) {
		return reject(new Error(INVALID_SYMBOL(symbol)));
	}
fork icon204
star icon229
watch icon14

+ 103 other calls in file

291
292
293
294
295
296
297
298
299
300

it('should reject the queued call when underlying pool rejects the request', () => {
    const pool = makePool_({limit: 1});
    const error = new Error('You shall not pass');
    underlyingPool.getBrowser
        .onSecondCall().callsFake(() => Promise.reject(error));

    return pool.getBrowser('bro')
        .then((browser) => {
            const secondRequest = pool.getBrowser('bro');
fork icon56
star icon556
watch icon11

+ 31 other calls in file

28
29
30
31
32
33
34
35
36
37
                    .then(() => this._callCommand(command, false));
            }

            return Promise.reject(new ClientBridgeError('Unable to inject client script'));
        })
        .catch((e) => Promise.reject(new ClientBridgeError(e.message)));
}

_clientMethodCommand(name, args) {
    const params = args.map(JSON.stringify).join(', ');
fork icon56
star icon556
watch icon11

+ 15 other calls in file

101
102
103
104
105
106
107
108
109
110
async function getOfficialModType(api, discovery = undefined) {
  const discoveryPath = (discovery?.path !== undefined)
    ? discovery.path
    : getDiscoveryPath(api);
  if (discoveryPath === undefined) {
    return Promise.reject(new GameNotDiscoveredException());
  }
  let gameVersion;
  try {
    gameVersion = await getGameVersion(discoveryPath, BAS_EXEC);
fork icon46
star icon28
watch icon7

+ 41 other calls in file

1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
])
    .spread((_count) => {
        docCount = _count;
        return _clientRequest('reindex', reindexQuery);
    })
    .catch((err) => Promise.reject(
        new TSError(err, {
            reason: `could not reindex for query ${JSON.stringify(reindexQuery)}`,
            context: {
                connection,
fork icon13
star icon48
watch icon10

+ 203 other calls in file

3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
traceParent._pushContext();
var result = tryCatch(yieldHandlers[i])(value);
traceParent._popContext();
if (result === errorObj) {
    traceParent._pushContext();
    var ret = Promise.reject(errorObj.e);
    traceParent._popContext();
    return ret;
}
var maybePromise = tryConvertToPromise(result, traceParent);
fork icon3
star icon16
watch icon0

+ 4 other calls in file

5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
function inspectionMapper(inspections) {
    var len = inspections.length;
    for (var i = 0; i < len; ++i) {
        var inspection = inspections[i];
        if (inspection.isRejected()) {
            return Promise.reject(inspection.error());
        }
        inspections[i] = inspection._settledValue;
    }
    return inspections;
fork icon2
star icon11
watch icon0

+ 19 other calls in file

4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
    var then = getThen(obj);
    if (then === errorObj) {
        if (originalPromise !== void 0 && canAttach(then.e)) {
            originalPromise._attachExtraTrace(then.e);
        }
        return Promise.reject(then.e);
    } else if (typeof then === "function") {
        return Promise$_doThenable(obj, then, originalPromise);
    }
}
fork icon1
star icon2
watch icon0

+ 3 other calls in file

220
221
222
223
224
225
226
227
228
229
  note: 'deprecated function?!',
})

const client = Global.clients[clientName]
if (!client) {
  return Promise.reject(new Error(`kth-node-redis: No such client: ${clientName}`))
}

return new Promise((resolve, reject) => {
  if (client.connected) {
fork icon0
star icon2
watch icon17

+ 11 other calls in file

268
269
270
271
272
273
274
275
276
277
        return Promise.delay(delay)
          .then(function() {
            return tryConnect(times - 1, delay * 2)
          })
      }
      return Promise.reject(err)
    })
}
log.info('Connecting to minitouch service')
// SH-03G can be very slow to start sometimes. Make sure we try long
fork icon0
star icon1
watch icon0

+ 3 other calls in file

355
356
357
358
359
360
361
362
363
364

var pid = this.pid

function kill(signal) {
  if (pid <= 0) {
    return Promise.reject(new Error('Minicap service pid is unknown'))
  }

  var signum = {
    SIGTERM: -15
fork icon0
star icon1
watch icon0

+ 3 other calls in file

163
164
165
166
167
168
169
170
171
172

ops.push(models.Tag.findOne({name: tag.name}, {transacting: transaction}).then(function (_tag) {
    if (!_tag) {
        return models.Tag.add(tag, _.extend(internal, {transacting: transaction}))
            .catch(function (error) {
                return Promise.reject({raw: error, model: 'tag', data: tag});
            });
    }

    return _tag;
fork icon0
star icon1
watch icon0

+ 4 other calls in file

47
48
49
50
51
52
53
54
55
56
57
58
59


handleErrors = function handleErrors(errorList) {
    var processedErrors = [];


    if (!_.isArray(errorList)) {
        return Promise.reject(errorList);
    }


    _.each(errorList, function (error) {
        if (!error.raw) {
fork icon0
star icon1
watch icon0

+ 2 other calls in file

20
21
22
23
24
25
26
27
28
29
            users.owner = user.toJSON();
        }
    });

    if (!users.owner) {
        return Promise.reject('Unable to find an owner');
    }

    return users;
});
fork icon0
star icon1
watch icon0