From 1e7a1c17ea2a91cbcc5859c0523688ea27d9bf25 Mon Sep 17 00:00:00 2001 From: Jelle De Loecker Date: Sat, 27 Apr 2024 19:47:12 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20`Pledge#getRejectedReason()`?= =?UTF-8?q?=20method?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + lib/pledge.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) 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 *