Opened 10 years ago
Closed 9 years ago
#11945 closed defect (wontfix)
Telling deferred.errback from deferred.cancel
Reported by: | Shashank | Owned by: | Mark Wubben |
---|---|---|---|
Priority: | high | Milestone: | tbd |
Component: | Core | Version: | 1.5 |
Keywords: | deferred, cancel | Cc: | |
Blocked By: | Blocking: |
Description
In my understanding, Deferred.cancel always fires errback (unless the deferred is already finished). How do I differentiate, in the error handler, whether it has been called due to an error or due to a cancellation?
In v 1.4 checking the error.message text was one solution (admittedly not the best solution, but it worked). In 1.5 there is no such error message that one could use.
Setting a flag on the error being returned or adding a flag to the deferred object itself can solve the problem, e.g. this change against the trunk Index: _base/Deferred.js =================================================================== --- _base/Deferred.js (revision 23174) +++ _base/Deferred.js (working copy) @@ -281,6 +281,7 @@
error = new Error(error);
} error.log = false;
+ error.isDeferredCancelled = true;
deferred.reject(error);
}
}
Change History (3)
comment:1 Changed 10 years ago by
Owner: | changed from anonymous to Kris Zyp |
---|
comment:2 Changed 9 years ago by
Owner: | changed from Kris Zyp to Mark Wubben |
---|---|
Status: | new → assigned |
comment:3 Changed 9 years ago by
Resolution: | → wontfix |
---|---|
Status: | assigned → closed |
With 1.8, cancel()
by default rejects with an instance of dojo/errors/CancelError
, so that's one way of knowing. This could be changed by the deferred though. Typically you'd only handle expected errors in the errbacks and let other errors bubble through the promise chain.
Closing this because there is no actual bug.
Not sure if this ticket is relevant anymore but assigning to Mark since it's about Deferreds.