Skip to content
Snippets Groups Projects
Commit afb7a0ee authored by Jorge Canizales's avatar Jorge Canizales
Browse files

Wrap parsing error appropriately before propagating.

parent e7209c58
No related branches found
No related tags found
No related merge requests found
...@@ -37,6 +37,20 @@ ...@@ -37,6 +37,20 @@
#import <RxLibrary/GRXWriteable.h> #import <RxLibrary/GRXWriteable.h>
#import <RxLibrary/GRXWriter+Transformations.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 { @implementation ProtoRPC {
id<GRXWriteable> _responseWriteable; id<GRXWriteable> _responseWriteable;
} }
...@@ -82,7 +96,7 @@ ...@@ -82,7 +96,7 @@
if (parsed) { if (parsed) {
[responsesWriteable writeValue:parsed]; [responsesWriteable writeValue:parsed];
} else { } else {
[weakSelf finishWithError:error]; [weakSelf finishWithError:ErrorForBadProto(value, responseClass, error)];
} }
} completionHandler:^(NSError *errorOrNil) { } completionHandler:^(NSError *errorOrNil) {
[responsesWriteable writesFinishedWithError:errorOrNil]; [responsesWriteable writesFinishedWithError:errorOrNil];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment