Fix crash in grpc_errorFromStatusCode

pull/16696/head
Muxi Yan 6 years ago
parent ccbad108e4
commit f83ca91702
  1. 2
      src/objective-c/GRPCClient/private/NSError+GRPC.h
  2. 16
      src/objective-c/GRPCClient/private/NSError+GRPC.m

@ -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

@ -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

Loading…
Cancel
Save