mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Merge branch 'charlesmchen/callConnectionGlitches'
This commit is contained in:
commit
e829541932
2 changed files with 33 additions and 17 deletions
|
@ -63,11 +63,11 @@ typedef void (^failureBlock)(NSURLSessionDataTask *task, NSError *error);
|
||||||
|
|
||||||
- (void)makeRequest:(TSRequest *)request
|
- (void)makeRequest:(TSRequest *)request
|
||||||
completionQueue:(dispatch_queue_t)completionQueue
|
completionQueue:(dispatch_queue_t)completionQueue
|
||||||
success:(TSNetworkManagerSuccess)success
|
success:(TSNetworkManagerSuccess)successBlock
|
||||||
failure:(TSNetworkManagerFailure)failureBlock
|
failure:(TSNetworkManagerFailure)failureBlock
|
||||||
{
|
{
|
||||||
OWSAssert(request);
|
OWSAssert(request);
|
||||||
OWSAssert(success);
|
OWSAssert(successBlock);
|
||||||
OWSAssert(failureBlock);
|
OWSAssert(failureBlock);
|
||||||
|
|
||||||
DDLogInfo(@"%@ Making request: %@", self.logTag, request);
|
DDLogInfo(@"%@ Making request: %@", self.logTag, request);
|
||||||
|
@ -77,12 +77,16 @@ typedef void (^failureBlock)(NSURLSessionDataTask *task, NSError *error);
|
||||||
&& ![request isKindOfClass:[TSContactsIntersectionRequest class]]
|
&& ![request isKindOfClass:[TSContactsIntersectionRequest class]]
|
||||||
&& ![request isKindOfClass:[TSAllocAttachmentRequest class]]) {
|
&& ![request isKindOfClass:[TSAllocAttachmentRequest class]]) {
|
||||||
// The SAE should only make requests directly related to message sending.
|
// The SAE should only make requests directly related to message sending.
|
||||||
OWSFail(@"%@ Making request: %@", self.logTag, request);
|
OWSFail(@"%@ Making unexpected request: %@", self.logTag, request);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void (^failure)(NSURLSessionDataTask *task, NSError *error) =
|
// TODO: Remove this logging when the call connection issues have been resolved.
|
||||||
[TSNetworkManager errorPrettifyingForFailureBlock:failureBlock];
|
TSNetworkManagerSuccess success = ^(NSURLSessionDataTask *task, id responseObject) {
|
||||||
|
DDLogInfo(@"%@ request succeeded : %@", self.logTag, request);
|
||||||
|
successBlock(task, responseObject);
|
||||||
|
};
|
||||||
|
TSNetworkManagerFailure failure = [TSNetworkManager errorPrettifyingForFailureBlock:failureBlock request:request];
|
||||||
|
|
||||||
AFHTTPSessionManager *sessionManager = [OWSSignalService sharedInstance].signalServiceSessionManager;
|
AFHTTPSessionManager *sessionManager = [OWSSignalService sharedInstance].signalServiceSessionManager;
|
||||||
// [OWSSignalService signalServiceSessionManager] always returns a new instance of
|
// [OWSSignalService signalServiceSessionManager] always returns a new instance of
|
||||||
|
@ -131,7 +135,11 @@ typedef void (^failureBlock)(NSURLSessionDataTask *task, NSError *error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (failureBlock)errorPrettifyingForFailureBlock:(failureBlock)failureBlock {
|
+ (failureBlock)errorPrettifyingForFailureBlock:(failureBlock)failureBlock request:(TSRequest *)request
|
||||||
|
{
|
||||||
|
OWSAssert(failureBlock);
|
||||||
|
OWSAssert(request);
|
||||||
|
|
||||||
return ^(NSURLSessionDataTask *_Nullable task, NSError *_Nonnull networkError) {
|
return ^(NSURLSessionDataTask *_Nullable task, NSError *_Nonnull networkError) {
|
||||||
NSInteger statusCode = [task statusCode];
|
NSInteger statusCode = [task statusCode];
|
||||||
NSError *error = [self errorWithHTTPCode:statusCode
|
NSError *error = [self errorWithHTTPCode:statusCode
|
||||||
|
@ -142,7 +150,7 @@ typedef void (^failureBlock)(NSURLSessionDataTask *task, NSError *error);
|
||||||
|
|
||||||
switch (statusCode) {
|
switch (statusCode) {
|
||||||
case 0: {
|
case 0: {
|
||||||
DDLogWarn(@"The network request failed because of a connectivity error.");
|
DDLogWarn(@"The network request failed because of a connectivity error: %@", request);
|
||||||
failureBlock(task,
|
failureBlock(task,
|
||||||
[self errorWithHTTPCode:statusCode
|
[self errorWithHTTPCode:statusCode
|
||||||
description:NSLocalizedString(@"ERROR_DESCRIPTION_NO_INTERNET",
|
description:NSLocalizedString(@"ERROR_DESCRIPTION_NO_INTERNET",
|
||||||
|
@ -153,27 +161,30 @@ typedef void (^failureBlock)(NSURLSessionDataTask *task, NSError *error);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 400: {
|
case 400: {
|
||||||
DDLogError(@"The request contains an invalid parameter : %@", networkError.debugDescription);
|
DDLogError(@"The request contains an invalid parameter : %@, %@", networkError.debugDescription, request);
|
||||||
failureBlock(task, error);
|
failureBlock(task, error);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 401: {
|
case 401: {
|
||||||
DDLogError(@"The server returned an error about the authorization header: %@",
|
DDLogError(@"The server returned an error about the authorization header: %@, %@",
|
||||||
networkError.debugDescription);
|
networkError.debugDescription,
|
||||||
|
request);
|
||||||
failureBlock(task, error);
|
failureBlock(task, error);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 403: {
|
case 403: {
|
||||||
DDLogError(@"The server returned an authentication failure: %@", networkError.debugDescription);
|
DDLogError(
|
||||||
|
@"The server returned an authentication failure: %@, %@", networkError.debugDescription, request);
|
||||||
failureBlock(task, error);
|
failureBlock(task, error);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 404: {
|
case 404: {
|
||||||
DDLogError(@"The requested resource could not be found: %@", networkError.debugDescription);
|
DDLogError(@"The requested resource could not be found: %@, %@", networkError.debugDescription, request);
|
||||||
failureBlock(task, error);
|
failureBlock(task, error);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 411: {
|
case 411: {
|
||||||
|
DDLogInfo(@"Multi-device pairing: %zd, %@, %@", statusCode, networkError.debugDescription, request);
|
||||||
failureBlock(task,
|
failureBlock(task,
|
||||||
[self errorWithHTTPCode:statusCode
|
[self errorWithHTTPCode:statusCode
|
||||||
description:NSLocalizedString(@"MULTIDEVICE_PAIRING_MAX_DESC", nil)
|
description:NSLocalizedString(@"MULTIDEVICE_PAIRING_MAX_DESC", nil)
|
||||||
|
@ -183,7 +194,7 @@ typedef void (^failureBlock)(NSURLSessionDataTask *task, NSError *error);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 413: {
|
case 413: {
|
||||||
DDLogWarn(@"Rate limit exceeded");
|
DDLogWarn(@"Rate limit exceeded: %@", request);
|
||||||
failureBlock(task,
|
failureBlock(task,
|
||||||
[self errorWithHTTPCode:statusCode
|
[self errorWithHTTPCode:statusCode
|
||||||
description:NSLocalizedString(@"REGISTRATION_ERROR", nil)
|
description:NSLocalizedString(@"REGISTRATION_ERROR", nil)
|
||||||
|
@ -193,7 +204,7 @@ typedef void (^failureBlock)(NSURLSessionDataTask *task, NSError *error);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 417: {
|
case 417: {
|
||||||
DDLogWarn(@"The number is already registered on a relay. Please unregister there first.");
|
DDLogWarn(@"The number is already registered on a relay. Please unregister there first: %@", request);
|
||||||
failureBlock(task,
|
failureBlock(task,
|
||||||
[self errorWithHTTPCode:statusCode
|
[self errorWithHTTPCode:statusCode
|
||||||
description:NSLocalizedString(@"REGISTRATION_ERROR", nil)
|
description:NSLocalizedString(@"REGISTRATION_ERROR", nil)
|
||||||
|
@ -203,13 +214,14 @@ typedef void (^failureBlock)(NSURLSessionDataTask *task, NSError *error);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 422: {
|
case 422: {
|
||||||
DDLogError(@"The registration was requested over an unknown transport: %@",
|
DDLogError(@"The registration was requested over an unknown transport: %@, %@",
|
||||||
networkError.debugDescription);
|
networkError.debugDescription,
|
||||||
|
request);
|
||||||
failureBlock(task, error);
|
failureBlock(task, error);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
|
DDLogWarn(@"Unknown error: %zd, %@, %@", statusCode, networkError.debugDescription, request);
|
||||||
failureBlock(task, error);
|
failureBlock(task, error);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -405,6 +405,10 @@ NSString *const kNSNotification_SocketManagerStateDidChange = @"kNSNotification_
|
||||||
backgroundTask = nil;
|
backgroundTask = nil;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
} else if ([message.path isEqualToString:@"/api/v1/queue/empty"]) {
|
||||||
|
// Queue is drained.
|
||||||
|
|
||||||
|
[self sendWebSocketMessageAcknowledgement:message];
|
||||||
} else {
|
} else {
|
||||||
DDLogWarn(@"%@ Unsupported WebSocket Request", self.logTag);
|
DDLogWarn(@"%@ Unsupported WebSocket Request", self.logTag);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue