aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objective-c/GRPCClient/private/NSError+GRPC.m
diff options
context:
space:
mode:
Diffstat (limited to 'src/objective-c/GRPCClient/private/NSError+GRPC.m')
-rw-r--r--src/objective-c/GRPCClient/private/NSError+GRPC.m20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/objective-c/GRPCClient/private/NSError+GRPC.m b/src/objective-c/GRPCClient/private/NSError+GRPC.m
index 199b2ebb6c..3eefed88d6 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];
- return [NSError errorWithDomain:kGRPCErrorDomain
- code:statusCode
- userInfo:@{
- NSLocalizedDescriptionKey : message,
- NSDebugDescriptionErrorKey : debugMessage
- }];
+ 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:userInfo];
}
@end