Merge pull request #14805 from Loghorn/add-catch-return-throw

Add catchReturn and catchThrow
This commit is contained in:
Paul van Brenk
2017-03-20 17:25:24 -07:00
committed by GitHub
3 changed files with 42 additions and 0 deletions
+2
View File
@@ -80,6 +80,8 @@ declare global {
// then: typeof Bluebird.prototype.then;
thenReturn: typeof Bluebird.prototype.thenReturn;
thenThrow: typeof Bluebird.prototype.thenThrow;
catchReturn: typeof Bluebird.prototype.catchReturn;
catchThrow: typeof Bluebird.prototype.catchThrow;
throw: typeof Bluebird.prototype.throw;
timeout: typeof Bluebird.prototype.timeout;
toJSON: typeof Bluebird.prototype.toJSON;
+9
View File
@@ -506,6 +506,15 @@ fooProm = fooProm.thenThrow(err);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
barProm = fooProm.catchReturn(bar);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// fooProm
fooProm = fooProm.catchThrow(err);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
str = fooProm.toString();
obj = fooProm.toJSON();
+31
View File
@@ -248,6 +248,37 @@ declare class Bluebird<R> implements Bluebird.Thenable<R>, Bluebird.Inspection<R
throw(reason: Error): Bluebird<R>;
thenThrow(reason: Error): Bluebird<R>;
/**
* Convenience method for:
*
* <code>
* .catch(function() {
* return value;
* });
* </code>
*
* in the case where `value` doesn't change its value. That means `value` is bound at the time of calling `.catchReturn()`
*/
catchReturn<U>(value: U): Bluebird<U>;
catchReturn<U>(predicate: (error: any) => boolean, value: U): Bluebird<U | R>;
catchReturn<E extends Error, U>(ErrorClass: new (...args: any[]) => E, value: U): Bluebird<U | R>;
catchReturn<U>(predicate: Object, value: U): Bluebird<U | R>;
/**
* Convenience method for:
*
* <code>
* .catch(function() {
* throw reason;
* });
* </code>
* Same limitations apply as with `.catchReturn()`.
*/
catchThrow(reason: Error): Bluebird<R>;
catchThrow(predicate: (error: any) => boolean, reason: Error): Bluebird<R>;
catchThrow<E extends Error, U>(ErrorClass: new (...args: any[]) => E, reason: Error): Bluebird<R>;
catchThrow(predicate: Object, reason: Error): Bluebird<R>;
/**
* Convert to String.
*/