aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objective-c/GRPCClient
diff options
context:
space:
mode:
authorGravatar ncteisen <ncteisen@gmail.com>2018-08-11 21:19:14 -0400
committerGravatar ncteisen <ncteisen@gmail.com>2018-08-11 21:19:14 -0400
commitc8503544233421764c0cd04870db3d03a95bd47b (patch)
tree15c4ff633797d310b59a16905c51b216f6fa37a7 /src/objective-c/GRPCClient
parente2a87dac6975b3cbf6e434e1bb5112269043653e (diff)
parente495476b1e31023637259883aa735fcc716c6adc (diff)
Merge branch 'master' of https://github.com/grpc/grpc into channelz-subchannels
Diffstat (limited to 'src/objective-c/GRPCClient')
-rw-r--r--src/objective-c/GRPCClient/GRPCCall.m23
-rw-r--r--src/objective-c/GRPCClient/private/GRPCWrappedCall.m8
-rw-r--r--src/objective-c/GRPCClient/private/NSError+GRPC.h4
-rw-r--r--src/objective-c/GRPCClient/private/NSError+GRPC.m10
4 files changed, 30 insertions, 15 deletions
diff --git a/src/objective-c/GRPCClient/GRPCCall.m b/src/objective-c/GRPCClient/GRPCCall.m
index 9783b06440..8ce88c7db2 100644
--- a/src/objective-c/GRPCClient/GRPCCall.m
+++ b/src/objective-c/GRPCClient/GRPCCall.m
@@ -220,17 +220,16 @@ static NSString *const kBearerPrefix = @"Bearer ";
}
- (void)cancel {
- [self
- maybeFinishWithError:[NSError
- errorWithDomain:kGRPCErrorDomain
- code:GRPCErrorCodeCancelled
- userInfo:@{NSLocalizedDescriptionKey : @"Canceled by app"}]];
-
if (!self.isWaitingForToken) {
[self cancelCall];
} else {
self.isWaitingForToken = NO;
}
+ [self
+ maybeFinishWithError:[NSError
+ errorWithDomain:kGRPCErrorDomain
+ code:GRPCErrorCodeCancelled
+ userInfo:@{NSLocalizedDescriptionKey : @"Canceled by app"}]];
}
- (void)maybeFinishWithError:(NSError *)errorOrNil {
@@ -292,6 +291,7 @@ static NSString *const kBearerPrefix = @"Bearer ";
// don't want to throw, because the app shouldn't crash for a behavior
// that's on the hands of any server to have. Instead we finish and ask
// the server to cancel.
+ [strongSelf cancelCall];
[strongSelf
maybeFinishWithError:[NSError errorWithDomain:kGRPCErrorDomain
code:GRPCErrorCodeResourceExhausted
@@ -300,7 +300,6 @@ static NSString *const kBearerPrefix = @"Bearer ";
@"Client does not have enough memory to "
@"hold the server response."
}]];
- [strongSelf cancelCall];
return;
}
[strongWriteable enqueueValue:data
@@ -530,13 +529,17 @@ static NSString *const kBearerPrefix = @"Bearer ";
}
- (void)connectivityChanged:(NSNotification *)note {
- [self maybeFinishWithError:[NSError errorWithDomain:kGRPCErrorDomain
+ // Cancel underlying call upon this notification
+ __strong GRPCCall *strongSelf = self;
+ if (strongSelf) {
+ [self cancelCall];
+ [self
+ maybeFinishWithError:[NSError errorWithDomain:kGRPCErrorDomain
code:GRPCErrorCodeUnavailable
userInfo:@{
NSLocalizedDescriptionKey : @"Connectivity lost."
}]];
- // Cancel underlying call upon this notification
- [self cancelCall];
+ }
}
@end
diff --git a/src/objective-c/GRPCClient/private/GRPCWrappedCall.m b/src/objective-c/GRPCClient/private/GRPCWrappedCall.m
index f28e494868..7781d27ca4 100644
--- a/src/objective-c/GRPCClient/private/GRPCWrappedCall.m
+++ b/src/objective-c/GRPCClient/private/GRPCWrappedCall.m
@@ -187,6 +187,7 @@
grpc_slice _details;
size_t _detailsCapacity;
grpc_metadata_array _trailers;
+ const char *_errorString;
}
- (instancetype)init {
@@ -200,6 +201,7 @@
_op.data.recv_status_on_client.status_details = &_details;
grpc_metadata_array_init(&_trailers);
_op.data.recv_status_on_client.trailing_metadata = &_trailers;
+ _op.data.recv_status_on_client.error_string = &_errorString;
if (handler) {
// Prevent reference cycle with _handler
__weak typeof(self) weakSelf = self;
@@ -207,8 +209,9 @@
__strong typeof(self) strongSelf = weakSelf;
if (strongSelf) {
char *details = grpc_slice_to_c_string(strongSelf->_details);
- NSError *error =
- [NSError grpc_errorFromStatusCode:strongSelf->_statusCode details:details];
+ NSError *error = [NSError grpc_errorFromStatusCode:strongSelf->_statusCode
+ details:details
+ errorString:strongSelf->_errorString];
NSDictionary *trailers =
[NSDictionary grpc_dictionaryFromMetadataArray:strongSelf->_trailers];
handler(error, trailers);
@@ -223,6 +226,7 @@
- (void)dealloc {
grpc_metadata_array_destroy(&_trailers);
grpc_slice_unref(_details);
+ gpr_free((void *)_errorString);
}
@end
diff --git a/src/objective-c/GRPCClient/private/NSError+GRPC.h b/src/objective-c/GRPCClient/private/NSError+GRPC.h
index e96b7297c2..a63e76ee4d 100644
--- a/src/objective-c/GRPCClient/private/NSError+GRPC.h
+++ b/src/objective-c/GRPCClient/private/NSError+GRPC.h
@@ -24,5 +24,7 @@
* Returns nil if the status code is OK. Otherwise, a NSError whose code is one of |GRPCErrorCode|
* and whose domain is |kGRPCErrorDomain|.
*/
-+ (instancetype)grpc_errorFromStatusCode:(grpc_status_code)statusCode details:(char *)details;
++ (instancetype)grpc_errorFromStatusCode:(grpc_status_code)statusCode
+ details:(char *)details
+ errorString:(const char *)errorString;
@end
diff --git a/src/objective-c/GRPCClient/private/NSError+GRPC.m b/src/objective-c/GRPCClient/private/NSError+GRPC.m
index c2e65e4d8a..199b2ebb6c 100644
--- a/src/objective-c/GRPCClient/private/NSError+GRPC.m
+++ b/src/objective-c/GRPCClient/private/NSError+GRPC.m
@@ -23,13 +23,19 @@
NSString *const kGRPCErrorDomain = @"io.grpc";
@implementation NSError (GRPC)
-+ (instancetype)grpc_errorFromStatusCode:(grpc_status_code)statusCode details:(char *)details {
++ (instancetype)grpc_errorFromStatusCode:(grpc_status_code)statusCode
+ details:(char *)details
+ errorString:(const char *)errorString {
if (statusCode == GRPC_STATUS_OK) {
return nil;
}
NSString *message = [NSString stringWithCString:details encoding:NSUTF8StringEncoding];
+ NSString *debugMessage = [NSString stringWithCString:errorString encoding:NSUTF8StringEncoding];
return [NSError errorWithDomain:kGRPCErrorDomain
code:statusCode
- userInfo:@{NSLocalizedDescriptionKey : message}];
+ userInfo:@{
+ NSLocalizedDescriptionKey : message,
+ NSDebugDescriptionErrorKey : debugMessage
+ }];
}
@end