diff --git a/CHANGELOG.md b/CHANGELOG.md index f734b60..5975c54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ * Add `Blast.isAppleWebkit` boolean * Add `Blast.environment` string property and `isProduction`, `isDevelopment` and `isStaging` booleans * Add `Optional` value-wrapper class +* Add `Pledge#getRejectedReason()` method ## 0.9.2 (2024-02-25) diff --git a/lib/pledge.js b/lib/pledge.js index 584496b..745f9b3 100644 --- a/lib/pledge.js +++ b/lib/pledge.js @@ -972,6 +972,24 @@ Pledge.setMethod(function getResolvedValue() { return this[RESOLVED_VALUE]; }); +/** + * Get the rejected reason of this pledge + * + * @author Jelle De Loecker + * @since 0.9.3 + * @version 0.9.3 + * + * @return {*} + */ +Pledge.setMethod(function getRejectedReason() { + + if (this[STATE] != REJECTED) { + return; + } + + return this[REJECTED_REASON]; +}); + /** * Resolve with the given value *