From afb7a0ee237fe1221f8c2c857387f82ff63c45c5 Mon Sep 17 00:00:00 2001 From: Jorge Canizales <jcanizales@google.com> Date: Thu, 3 Sep 2015 02:39:36 -0700 Subject: [PATCH] Wrap parsing error appropriately before propagating. --- src/objective-c/ProtoRPC/ProtoRPC.m | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/objective-c/ProtoRPC/ProtoRPC.m b/src/objective-c/ProtoRPC/ProtoRPC.m index 61fc0e3531..735ce0bdb5 100644 --- a/src/objective-c/ProtoRPC/ProtoRPC.m +++ b/src/objective-c/ProtoRPC/ProtoRPC.m @@ -37,6 +37,20 @@ #import <RxLibrary/GRXWriteable.h> #import <RxLibrary/GRXWriter+Transformations.h> +static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsingError) { + NSDictionary *info = @{ + NSLocalizedDescriptionKey: @"Unable to parse response from the server", + NSLocalizedRecoverySuggestionErrorKey: @"Retry with exponential backoff", + NSUnderlyingErrorKey: parsingError, + @"Expected class": expectedClass, + @"Received value": proto, + }; + // TODO(jcanizales): Use kGRPCErrorDomain and GRPCErrorCodeInternal when they're public. + return [NSError errorWithDomain:@"io.grpc" + code:13 + userInfo:info]; +} + @implementation ProtoRPC { id<GRXWriteable> _responseWriteable; } @@ -82,7 +96,7 @@ if (parsed) { [responsesWriteable writeValue:parsed]; } else { - [weakSelf finishWithError:error]; + [weakSelf finishWithError:ErrorForBadProto(value, responseClass, error)]; } } completionHandler:^(NSError *errorOrNil) { [responsesWriteable writesFinishedWithError:errorOrNil]; -- GitLab