aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objective-c/GRPCClient
diff options
context:
space:
mode:
authorGravatar Muxi Yan <mxyan@google.com>2018-09-25 10:52:31 -0700
committerGravatar Muxi Yan <mxyan@google.com>2018-09-25 10:52:31 -0700
commitf83ca91702f666b6e8fb07e5004817e60b390dd7 (patch)
tree3beaef1fdf287eb6b93c54136a18a23486707c7a /src/objective-c/GRPCClient
parentccbad108e45afb7c4fb361202cc0bae5ad7e5da2 (diff)
Fix crash in grpc_errorFromStatusCode
Diffstat (limited to 'src/objective-c/GRPCClient')
-rw-r--r--src/objective-c/GRPCClient/private/NSError+GRPC.h2
-rw-r--r--src/objective-c/GRPCClient/private/NSError+GRPC.m16
2 files changed, 10 insertions, 8 deletions
diff --git a/src/objective-c/GRPCClient/private/NSError+GRPC.h b/src/objective-c/GRPCClient/private/NSError+GRPC.h
index a63e76ee4d..fb05638b78 100644
--- a/src/objective-c/GRPCClient/private/NSError+GRPC.h
+++ b/src/objective-c/GRPCClient/private/NSError+GRPC.h
@@ -25,6 +25,6 @@
* and whose domain is |kGRPCErrorDomain|.
*/
+ (instancetype)grpc_errorFromStatusCode:(grpc_status_code)statusCode
- details:(char *)details
+ details:(const 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 199b2ebb6c..c0f7e019a2 100644
--- a/src/objective-c/GRPCClient/private/NSError+GRPC.m
+++ b/src/objective-c/GRPCClient/private/NSError+GRPC.m
@@ -24,18 +24,20 @@ NSString *const kGRPCErrorDomain = @"io.grpc";
@implementation NSError (GRPC)
+ (instancetype)grpc_errorFromStatusCode:(grpc_status_code)statusCode
- details:(char *)details
+ details:(const 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];
+ NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
+ if (details) {
+ userInfo[NSLocalizedDescriptionKey] = [NSString stringWithCString:details encoding:NSUTF8StringEncoding];
+ }
+ if (errorString) {
+ userInfo[NSDebugDescriptionErrorKey] = [NSString stringWithCString:errorString encoding:NSUTF8StringEncoding];
+ }
return [NSError errorWithDomain:kGRPCErrorDomain
code:statusCode
- userInfo:@{
- NSLocalizedDescriptionKey : message,
- NSDebugDescriptionErrorKey : debugMessage
- }];
+ userInfo:userInfo];
}
@end