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

Propagate parsing error if we get a bad response

parent ddb58ea5
Branches
Tags
No related merge requests found
...@@ -65,14 +65,25 @@ ...@@ -65,14 +65,25 @@
} }
// A writer that serializes the proto messages to send. // A writer that serializes the proto messages to send.
GRXWriter *bytesWriter = [requestsWriter map:^id(GPBMessage *proto) { GRXWriter *bytesWriter = [requestsWriter map:^id(GPBMessage *proto) {
// TODO(jcanizales): Fail with an understandable error message if the requestsWriter isn't if (![proto isKindOfClass:GPBMessage.class]) {
// sending GPBMessages. [NSException raise:NSInvalidArgumentException
format:@"Request must be a proto message: %@", proto];
}
return [proto data]; return [proto data];
}]; }];
if ((self = [super initWithHost:host path:method.HTTPPath requestsWriter:bytesWriter])) { if ((self = [super initWithHost:host path:method.HTTPPath requestsWriter:bytesWriter])) {
__weak ProtoRPC *weakSelf = self;
// A writeable that parses the proto messages received. // A writeable that parses the proto messages received.
_responseWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) { _responseWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
[responsesWriteable writeValue:[responseClass parseFromData:value error:NULL]]; // TODO(jcanizales): This is done in the main thread, and needs to happen in another thread.
NSError *error = nil;
id parsed = [responseClass parseFromData:value error:&error];
if (parsed) {
[responsesWriteable writeValue:parsed];
} else {
[weakSelf finishWithError: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.
Please to comment