From 413d2ba88a3b07b528c261afa383e198c2508b83 Mon Sep 17 00:00:00 2001 From: Marat Al Date: Sun, 6 Mar 2022 23:43:50 +0100 Subject: [PATCH 1/2] Added `cause` property to `ARTErrorInfo` as a reflection of `NSUnderlyingErrorKey` value from `NSError.userInfo`. --- Source/ARTStatus.h | 1 + Source/ARTStatus.m | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/Source/ARTStatus.h b/Source/ARTStatus.h index 812c11863..9feb71552 100644 --- a/Source/ARTStatus.h +++ b/Source/ARTStatus.h @@ -191,6 +191,7 @@ FOUNDATION_EXPORT NSString *const ARTAblyMessageNoMeansToRenewToken; @interface ARTErrorInfo : NSError @property (readonly) NSString *message; +@property (nullable, readonly) NSError *cause; @property (nullable, readonly) NSString *reason; @property (readonly) NSInteger statusCode; @property (nullable, readonly) NSString *href; diff --git a/Source/ARTStatus.m b/Source/ARTStatus.m index f06f35e2d..cef2eef6c 100644 --- a/Source/ARTStatus.m +++ b/Source/ARTStatus.m @@ -96,6 +96,10 @@ - (NSString *)reason { return reason; } +- (NSError *)cause { + return self.userInfo[NSUnderlyingErrorKey]; +} + - (NSInteger)statusCode { return [self artStatusCode]; } From 6fb1f954a09362e469ccdcd596e3a99f67daadaa Mon Sep 17 00:00:00 2001 From: Marat Al Date: Mon, 7 Mar 2022 00:05:54 +0100 Subject: [PATCH 2/2] Converted `cause` to `ARTErrorInfo` --- Source/ARTStatus.h | 2 +- Source/ARTStatus.m | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Source/ARTStatus.h b/Source/ARTStatus.h index 9feb71552..38e7559e2 100644 --- a/Source/ARTStatus.h +++ b/Source/ARTStatus.h @@ -191,11 +191,11 @@ FOUNDATION_EXPORT NSString *const ARTAblyMessageNoMeansToRenewToken; @interface ARTErrorInfo : NSError @property (readonly) NSString *message; -@property (nullable, readonly) NSError *cause; @property (nullable, readonly) NSString *reason; @property (readonly) NSInteger statusCode; @property (nullable, readonly) NSString *href; @property (nullable, readonly) NSString *requestId; +@property (nullable, readonly) ARTErrorInfo *cause; + (ARTErrorInfo *)createWithCode:(NSInteger)code message:(NSString *)message; + (ARTErrorInfo *)createWithCode:(NSInteger)code status:(NSInteger)status message:(NSString *)message; diff --git a/Source/ARTStatus.m b/Source/ARTStatus.m index cef2eef6c..f32ae7b39 100644 --- a/Source/ARTStatus.m +++ b/Source/ARTStatus.m @@ -96,8 +96,12 @@ - (NSString *)reason { return reason; } -- (NSError *)cause { - return self.userInfo[NSUnderlyingErrorKey]; +- (ARTErrorInfo *)cause { + NSError *underlyingError = self.userInfo[NSUnderlyingErrorKey]; + if (underlyingError == nil) { + return nil; + } + return [ARTErrorInfo createFromNSError:underlyingError]; } - (NSInteger)statusCode {