File tree Expand file tree Collapse file tree 3 files changed +30
-0
lines changed Expand file tree Collapse file tree 3 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,14 @@ extension Promise {
13
13
}
14
14
}
15
15
16
+ /**
17
+ - Returns: The error with which this promise was rejected; `nil` if this promise is not rejected.
18
+ Alternative for the cases where the Swift compiler gets confused over the name of the `error` property
19
+ */
20
+ public var errorValue : ErrorType ? {
21
+ return self . error
22
+ }
23
+
16
24
/**
17
25
- Returns: `true` if the promise has not yet resolved.
18
26
*/
Original file line number Diff line number Diff line change @@ -390,6 +390,14 @@ public class Promise<T> {
390
390
}
391
391
}
392
392
393
+ /**
394
+ Provides an alias for the `error` function for cases where the Swift compiler gets into trouble inferring the right
395
+ types. If `error` does not work, consider using `onError` instead which does the same thing.
396
+ */
397
+ public func onError( policy policy: ErrorPolicy = . AllErrorsExceptCancellation, _ body: ( ErrorType ) -> Void ) {
398
+ error ( policy: policy, body)
399
+ }
400
+
393
401
/**
394
402
The provided closure is executed when this promise is rejected giving you
395
403
an opportunity to recover from the error and continue the promise chain.
Original file line number Diff line number Diff line change @@ -116,6 +116,20 @@ class ErrorHandlingTests_Swift: XCTestCase {
116
116
}
117
117
}
118
118
119
+
120
+ // an alias called `onError` exists for the `error` function
121
+ func test7( ) {
122
+ twice { promise, ex in
123
+ PMKUnhandledErrorHandler = { err in
124
+ XCTFail ( )
125
+ }
126
+
127
+ promise. onError { error in
128
+ ex. fulfill ( )
129
+ }
130
+ }
131
+ }
132
+
119
133
func testDoubleRejectDoesNotTriggerUnhandler( ) {
120
134
enum Error : ErrorType {
121
135
case Test
You can’t perform that action at this time.
0 commit comments