Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extending ErrorInfo with href and requestId #1147

Merged
merged 15 commits into from
Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Ably.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@
96E408481A3895E800087F77 /* ARTWebSocketTransport.m in Sources */ = {isa = PBXBuildFile; fileRef = 96E408461A3895E800087F77 /* ARTWebSocketTransport.m */; };
D3AD0EBD215E2FB000312105 /* ARTNSString+ARTUtil.h in Headers */ = {isa = PBXBuildFile; fileRef = D3AD0EBB215E2FB000312105 /* ARTNSString+ARTUtil.h */; };
D3AD0EBE215E2FB000312105 /* ARTNSString+ARTUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = D3AD0EBC215E2FB000312105 /* ARTNSString+ARTUtil.m */; };
D54C55972692F8E200729EC4 /* ARTNSMutableURLRequest+ARTUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = D54C55952692F8E200729EC4 /* ARTNSMutableURLRequest+ARTUtils.h */; };
D54C55982692F8E200729EC4 /* ARTNSMutableURLRequest+ARTUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = D54C55952692F8E200729EC4 /* ARTNSMutableURLRequest+ARTUtils.h */; };
D54C55992692F8E200729EC4 /* ARTNSMutableURLRequest+ARTUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = D54C55952692F8E200729EC4 /* ARTNSMutableURLRequest+ARTUtils.h */; };
D54C559A2692F8E200729EC4 /* ARTNSMutableURLRequest+ARTUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = D54C55962692F8E200729EC4 /* ARTNSMutableURLRequest+ARTUtils.m */; };
D54C559B2692F8E200729EC4 /* ARTNSMutableURLRequest+ARTUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = D54C55962692F8E200729EC4 /* ARTNSMutableURLRequest+ARTUtils.m */; };
D54C559C2692F8E200729EC4 /* ARTNSMutableURLRequest+ARTUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = D54C55962692F8E200729EC4 /* ARTNSMutableURLRequest+ARTUtils.m */; };
D54C559F2693014D00729EC4 /* ARTNSError+ARTUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = D54C559D2693014D00729EC4 /* ARTNSError+ARTUtils.h */; };
D54C55A02693014D00729EC4 /* ARTNSError+ARTUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = D54C559D2693014D00729EC4 /* ARTNSError+ARTUtils.h */; };
D54C55A12693014D00729EC4 /* ARTNSError+ARTUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = D54C559D2693014D00729EC4 /* ARTNSError+ARTUtils.h */; };
D54C55A22693014D00729EC4 /* ARTNSError+ARTUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = D54C559E2693014D00729EC4 /* ARTNSError+ARTUtils.m */; };
D54C55A32693014D00729EC4 /* ARTNSError+ARTUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = D54C559E2693014D00729EC4 /* ARTNSError+ARTUtils.m */; };
D54C55A42693014D00729EC4 /* ARTNSError+ARTUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = D54C559E2693014D00729EC4 /* ARTNSError+ARTUtils.m */; };
D7093C0F219E2DB200723F17 /* Ably.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D710D45B219495E2008F54AD /* Ably.framework */; };
D7093C19219E465300723F17 /* TestUtilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = 856AAC961B6E30C800B07119 /* TestUtilities.swift */; };
D7093C1A219E465C00723F17 /* NSObject+TestSuite.m in Sources */ = {isa = PBXBuildFile; fileRef = D780846D1C68B3E50083009D /* NSObject+TestSuite.m */; };
Expand Down Expand Up @@ -830,6 +842,10 @@
96E408461A3895E800087F77 /* ARTWebSocketTransport.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ARTWebSocketTransport.m; sourceTree = "<group>"; };
D3AD0EBB215E2FB000312105 /* ARTNSString+ARTUtil.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "ARTNSString+ARTUtil.h"; path = "Private/ARTNSString+ARTUtil.h"; sourceTree = "<group>"; };
D3AD0EBC215E2FB000312105 /* ARTNSString+ARTUtil.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = "ARTNSString+ARTUtil.m"; path = "Private/ARTNSString+ARTUtil.m"; sourceTree = "<group>"; };
D54C55952692F8E200729EC4 /* ARTNSMutableURLRequest+ARTUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ARTNSMutableURLRequest+ARTUtils.h"; sourceTree = "<group>"; };
D54C55962692F8E200729EC4 /* ARTNSMutableURLRequest+ARTUtils.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "ARTNSMutableURLRequest+ARTUtils.m"; sourceTree = "<group>"; };
D54C559D2693014D00729EC4 /* ARTNSError+ARTUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ARTNSError+ARTUtils.h"; sourceTree = "<group>"; };
D54C559E2693014D00729EC4 /* ARTNSError+ARTUtils.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "ARTNSError+ARTUtils.m"; sourceTree = "<group>"; };
D7093C0A219E2DB200723F17 /* Ably-macOS-Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Ably-macOS-Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
D7093C0E219E2DB200723F17 /* Info-macOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-macOS.plist"; sourceTree = "<group>"; };
D7093C60219EE1AE00723F17 /* Ably-tvOS-Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Ably-tvOS-Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -1413,6 +1429,10 @@
D798555E23ECCDAF00946BE2 /* ARTVCDiffDecoder.h */,
D73B655323EF2B2900D459A6 /* ARTDeltaCodec.h */,
D73B655423EF2B2900D459A6 /* ARTDeltaCodec.m */,
D54C55952692F8E200729EC4 /* ARTNSMutableURLRequest+ARTUtils.h */,
D54C55962692F8E200729EC4 /* ARTNSMutableURLRequest+ARTUtils.m */,
D54C559D2693014D00729EC4 /* ARTNSError+ARTUtils.h */,
D54C559E2693014D00729EC4 /* ARTNSError+ARTUtils.m */,
);
name = Utilities;
sourceTree = "<group>";
Expand Down Expand Up @@ -1573,6 +1593,7 @@
EB89D4011C61C10E007FA5B7 /* ARTChannels+Private.h in Headers */,
D74CBC03212EB58700D090E4 /* ARTNSHTTPURLResponse+ARTPaginated.h in Headers */,
1CD8DC9F1B1C7315007EAF36 /* ARTDefault.h in Headers */,
D54C559F2693014D00729EC4 /* ARTNSError+ARTUtils.h in Headers */,
D70EECAC1FEAF331008A50CD /* ARTPendingMessage.h in Headers */,
D7D8F8211BC2BE16009718F2 /* ARTAuthOptions.h in Headers */,
EB82F8511C59D29B00661917 /* ARTDataEncoder.h in Headers */,
Expand All @@ -1586,6 +1607,7 @@
D777EEE42063A64E002EBA03 /* ARTNSMutableRequest+ARTPush.h in Headers */,
EB20F8D71C653F2300EF3978 /* ARTPresence+Private.h in Headers */,
D7F1D3771BF4DE72001A4B5E /* ARTRealtimePresence.h in Headers */,
D54C55972692F8E200729EC4 /* ARTNSMutableURLRequest+ARTUtils.h in Headers */,
1C578E1F1B3435CA00EF46EC /* ARTFallback.h in Headers */,
EB7617721CB6CBFF00D0981E /* ARTRealtimePresence+Private.h in Headers */,
EBFFAC1B1E97EF68003E7326 /* ARTPushAdmin+Private.h in Headers */,
Expand Down Expand Up @@ -1701,6 +1723,7 @@
D710D69221949EFF008F54AD /* ARTJsonEncoder.h in Headers */,
D710D5B921949D4F008F54AD /* ARTTokenParams+Private.h in Headers */,
D710D51821949C42008F54AD /* ARTPushChannelSubscription.h in Headers */,
D54C55A02693014D00729EC4 /* ARTNSError+ARTUtils.h in Headers */,
D710D4B421949B47008F54AD /* ARTAuth+Private.h in Headers */,
D710D4C221949B9C008F54AD /* ARTRealtimeTransport.h in Headers */,
D710D58121949D28008F54AD /* ARTTokenRequest.h in Headers */,
Expand All @@ -1714,6 +1737,7 @@
D710D58F21949D29008F54AD /* ARTStats.h in Headers */,
D710D4B521949B47008F54AD /* ARTRestPresence+Private.h in Headers */,
D710D4A921949ADF008F54AD /* ARTRestChannels.h in Headers */,
D54C55982692F8E200729EC4 /* ARTNSMutableURLRequest+ARTUtils.h in Headers */,
D710D4D821949BF9008F54AD /* ARTRealtimePresence.h in Headers */,
D710D48F21949AAE008F54AD /* ARTRest.h in Headers */,
D710D5B821949D4F008F54AD /* ARTAuthOptions+Private.h in Headers */,
Expand Down Expand Up @@ -1829,6 +1853,7 @@
D710D69C21949F00008F54AD /* ARTJsonEncoder.h in Headers */,
D710D5C921949D50008F54AD /* ARTTokenParams+Private.h in Headers */,
D710D52A21949C44008F54AD /* ARTPushChannelSubscription.h in Headers */,
D54C55A12693014D00729EC4 /* ARTNSError+ARTUtils.h in Headers */,
D710D4BA21949B48008F54AD /* ARTAuth+Private.h in Headers */,
D710D4C621949B9D008F54AD /* ARTRealtimeTransport.h in Headers */,
D710D5A721949D2A008F54AD /* ARTTokenRequest.h in Headers */,
Expand All @@ -1842,6 +1867,7 @@
D710D5B521949D2A008F54AD /* ARTStats.h in Headers */,
D710D4BB21949B48008F54AD /* ARTRestPresence+Private.h in Headers */,
D710D4AF21949AE0008F54AD /* ARTRestChannels.h in Headers */,
D54C55992692F8E200729EC4 /* ARTNSMutableURLRequest+ARTUtils.h in Headers */,
D710D4E821949BFB008F54AD /* ARTRealtimePresence.h in Headers */,
D710D49121949AAF008F54AD /* ARTRest.h in Headers */,
D710D5C821949D50008F54AD /* ARTAuthOptions+Private.h in Headers */,
Expand Down Expand Up @@ -2245,6 +2271,7 @@
D7DEAFD21E65926D00D23F24 /* ARTLocalDevice.m in Sources */,
EB2D84FD1CD769B800F23CDA /* ARTOSReachability.m in Sources */,
D746AE481BBD6FE9003ECEF8 /* ARTQueuedMessage.m in Sources */,
D54C559A2692F8E200729EC4 /* ARTNSMutableURLRequest+ARTUtils.m in Sources */,
D746AE3D1BBC5AE1003ECEF8 /* ARTRealtimeChannel.m in Sources */,
96A507A21A377AA50077CDF8 /* ARTPresenceMessage.m in Sources */,
D74CBC0F212F076000D090E4 /* ARTConstants.m in Sources */,
Expand Down Expand Up @@ -2301,6 +2328,7 @@
D73B655823EF2B2900D459A6 /* ARTDeltaCodec.m in Sources */,
D768C6AD1E4B5B0200436011 /* ARTDevicePushDetails.m in Sources */,
1C6C18A41ADFDAB100AB79E4 /* ARTLog.m in Sources */,
D54C55A22693014D00729EC4 /* ARTNSError+ARTUtils.m in Sources */,
D70EAAEE1BC3376200CD8B9E /* ARTRestChannel.m in Sources */,
EB1B540522F8DA05006A59AC /* ARTQueuedDealloc.m in Sources */,
D746AE291BBB61C9003ECEF8 /* ARTPresence.m in Sources */,
Expand Down Expand Up @@ -2388,6 +2416,7 @@
D710D49521949AC2008F54AD /* ARTRest.m in Sources */,
D710D53921949C54008F54AD /* ARTNSMutableRequest+ARTPush.m in Sources */,
D710D66D21949E78008F54AD /* ARTLog.m in Sources */,
D54C559B2692F8E200729EC4 /* ARTNSMutableURLRequest+ARTUtils.m in Sources */,
D710D5D721949D78008F54AD /* ARTChannels.m in Sources */,
D710D4F221949C0D008F54AD /* ARTPendingMessage.m in Sources */,
D710D55F21949C97008F54AD /* ARTPushActivationState.m in Sources */,
Expand Down Expand Up @@ -2444,6 +2473,7 @@
D710D62D21949E03008F54AD /* ARTHttp.m in Sources */,
D710D63021949E03008F54AD /* ARTPaginatedResult.m in Sources */,
D710D5E121949D78008F54AD /* ARTStatus.m in Sources */,
D54C55A32693014D00729EC4 /* ARTNSError+ARTUtils.m in Sources */,
EB1B540622F8DA05006A59AC /* ARTQueuedDealloc.m in Sources */,
D710D53321949C54008F54AD /* ARTPushChannelSubscription.m in Sources */,
D710D67121949E79008F54AD /* ARTOSReachability.m in Sources */,
Expand Down Expand Up @@ -2471,6 +2501,7 @@
D710D49721949AC3008F54AD /* ARTRest.m in Sources */,
D710D54B21949C55008F54AD /* ARTNSMutableRequest+ARTPush.m in Sources */,
D710D65321949E77008F54AD /* ARTLog.m in Sources */,
D54C559C2692F8E200729EC4 /* ARTNSMutableURLRequest+ARTUtils.m in Sources */,
D710D5FD21949D79008F54AD /* ARTChannels.m in Sources */,
D710D50221949C0E008F54AD /* ARTPendingMessage.m in Sources */,
D710D56521949C98008F54AD /* ARTPushActivationState.m in Sources */,
Expand Down Expand Up @@ -2527,6 +2558,7 @@
D710D63D21949E04008F54AD /* ARTHttp.m in Sources */,
D710D64021949E04008F54AD /* ARTPaginatedResult.m in Sources */,
D710D60721949D79008F54AD /* ARTStatus.m in Sources */,
D54C55A42693014D00729EC4 /* ARTNSError+ARTUtils.m in Sources */,
EB1B540722F8DA05006A59AC /* ARTQueuedDealloc.m in Sources */,
D710D54521949C55008F54AD /* ARTPushChannelSubscription.m in Sources */,
D710D65721949E77008F54AD /* ARTOSReachability.m in Sources */,
Expand Down
24 changes: 24 additions & 0 deletions Source/ARTNSError+ARTUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// NSError+ARTUtils.h
// Ably
//
// Created by Łukasz Szyszkowski on 05/07/2021.
// Copyright © 2021 Ably. All rights reserved.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface NSError (ARTUtils)

@property (nullable, readonly) NSString *requestId;

/**
if `requestId` is nil, pointer to this instance is returned. If `requestId` is NOT nil, pointer to new instance of NSError is returned
*/
- (NSError *)errorWithRequestId:(nullable NSString *)requestId;

@end

NS_ASSUME_NONNULL_END
29 changes: 29 additions & 0 deletions Source/ARTNSError+ARTUtils.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// NSError+ARTUtils.m
// Ably
//
// Created by Łukasz Szyszkowski on 05/07/2021.
// Copyright © 2021 Ably. All rights reserved.
//

#import "ARTNSError+ARTUtils.h"
#import "ARTStatus.h"

@implementation NSError (ARTUtils)

- (NSError *)errorWithRequestId:(NSString *)requestId {
if (requestId == nil) {
return self;
}

maratal marked this conversation as resolved.
Show resolved Hide resolved
NSMutableDictionary *mutableInfo = [NSMutableDictionary dictionaryWithDictionary:self.userInfo];
mutableInfo[ARTErrorInfoRequestIdKey] = requestId;

return [NSError errorWithDomain:self.domain code:self.code userInfo:mutableInfo];
}

- (NSString *)requestId {
return self.userInfo[ARTErrorInfoRequestIdKey];
}

@end
19 changes: 19 additions & 0 deletions Source/ARTNSMutableURLRequest+ARTUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// NSMutableURLRequest+ARTUtils.h
// Ably
//
// Created by Łukasz Szyszkowski on 05/07/2021.
// Copyright © 2021 Ably. All rights reserved.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface NSMutableURLRequest (ARTUtils)

- (void)appendQueryItem:(NSURLQueryItem *)item;

@end

NS_ASSUME_NONNULL_END
29 changes: 29 additions & 0 deletions Source/ARTNSMutableURLRequest+ARTUtils.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// NSMutableURLRequest+ARTUtils.m
// Ably
//
// Created by Łukasz Szyszkowski on 05/07/2021.
// Copyright © 2021 Ably. All rights reserved.
//

#import "ARTNSMutableURLRequest+ARTUtils.h"

@implementation NSMutableURLRequest (ARTUtils)

-(void)appendQueryItem:(NSURLQueryItem *)item {
NSURLComponents *components = [NSURLComponents componentsWithURL:self.URL resolvingAgainstBaseURL:YES];
maratal marked this conversation as resolved.
Show resolved Hide resolved
if(components == nil) {
return;
}

NSMutableArray<NSURLQueryItem *> *mutableQueryItems = [NSMutableArray arrayWithArray:components.queryItems];
[mutableQueryItems addObject:item];
components.queryItems = mutableQueryItems;

NSURL *modifiedURL = components.URL;
if (modifiedURL != nil) {
self.URL = modifiedURL;
}
}

@end
6 changes: 4 additions & 2 deletions Source/ARTRest+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ NS_ASSUME_NONNULL_BEGIN
/// ARTRest private methods that are used internally and for internal testing
@interface ARTRestInternal : NSObject <ARTRestProtocol, ARTHTTPAuthenticatedExecutor>

typedef void (^CompletionBlock)(NSHTTPURLResponse * _Nullable, NSData * _Nullable, NSError * _Nullable);

maratal marked this conversation as resolved.
Show resolved Hide resolved
@property (nonatomic, strong, readonly) ARTRestChannelsInternal *channels;
@property (nonatomic, strong, readonly) ARTAuthInternal *auth;
@property (nonatomic, strong, readonly) ARTPushInternal *push;
Expand Down Expand Up @@ -57,11 +59,11 @@ NS_ASSUME_NONNULL_BEGIN

// MARK: ARTHTTPExecutor

- (nullable NSObject<ARTCancellable> *)executeRequest:(NSURLRequest *)request completion:(nullable void (^)(NSHTTPURLResponse *_Nullable, NSData *_Nullable, NSError *_Nullable))callback;
- (nullable NSObject<ARTCancellable> *)executeRequest:(NSURLRequest *)request completion:(nullable CompletionBlock)callback;

// MARK: Internal

- (nullable NSObject<ARTCancellable> *)executeRequest:(NSMutableURLRequest *)request withAuthOption:(ARTAuthentication)authOption completion:(void (^)(NSHTTPURLResponse *_Nullable, NSData * _Nullable, NSError * _Nullable))callback;
- (nullable NSObject<ARTCancellable> *)executeRequest:(NSMutableURLRequest *)request withAuthOption:(ARTAuthentication)authOption completion:(CompletionBlock)callback;

- (nullable NSObject<ARTCancellable> *)internetIsUp:(void (^)(BOOL isUp))cb;

Expand Down
Loading