|
|
@ -24,18 +24,20 @@ NSString *const kGRPCErrorDomain = @"io.grpc"; |
|
|
|
|
|
|
|
|
|
|
|
@implementation NSError (GRPC) |
|
|
|
@implementation NSError (GRPC) |
|
|
|
+ (instancetype)grpc_errorFromStatusCode:(grpc_status_code)statusCode |
|
|
|
+ (instancetype)grpc_errorFromStatusCode:(grpc_status_code)statusCode |
|
|
|
details:(char *)details |
|
|
|
details:(const char *)details |
|
|
|
errorString:(const char *)errorString { |
|
|
|
errorString:(const char *)errorString { |
|
|
|
if (statusCode == GRPC_STATUS_OK) { |
|
|
|
if (statusCode == GRPC_STATUS_OK) { |
|
|
|
return nil; |
|
|
|
return nil; |
|
|
|
} |
|
|
|
} |
|
|
|
NSString *message = [NSString stringWithCString:details encoding:NSUTF8StringEncoding]; |
|
|
|
NSMutableDictionary *userInfo = [NSMutableDictionary dictionary]; |
|
|
|
NSString *debugMessage = [NSString stringWithCString:errorString encoding:NSUTF8StringEncoding]; |
|
|
|
if (details) { |
|
|
|
|
|
|
|
userInfo[NSLocalizedDescriptionKey] = [NSString stringWithCString:details encoding:NSUTF8StringEncoding]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (errorString) { |
|
|
|
|
|
|
|
userInfo[NSDebugDescriptionErrorKey] = [NSString stringWithCString:errorString encoding:NSUTF8StringEncoding]; |
|
|
|
|
|
|
|
} |
|
|
|
return [NSError errorWithDomain:kGRPCErrorDomain |
|
|
|
return [NSError errorWithDomain:kGRPCErrorDomain |
|
|
|
code:statusCode |
|
|
|
code:statusCode |
|
|
|
userInfo:@{ |
|
|
|
userInfo:userInfo]; |
|
|
|
NSLocalizedDescriptionKey : message, |
|
|
|
|
|
|
|
NSDebugDescriptionErrorKey : debugMessage |
|
|
|
|
|
|
|
}]; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
@end |
|
|
|
@end |
|
|
|