def _try_response_parse(cls, proto, response, traps=None): """Parses the Protobuf response from the validator. Uses "error traps" to send back any HTTP error triggered by a Protobuf status, both those common to many handlers, and specified individually. """ parsed = proto() parsed.ParseFromString(response) traps = traps or [] try: traps.append(error_handlers.Unknown(proto.INTERNAL_ERROR)) except AttributeError: # Not every protobuf has every status enum, so pass AttributeErrors pass try: traps.append(error_handlers.NotReady(proto.NOT_READY)) except AttributeError: pass try: traps.append(error_handlers.MissingHead(proto.NO_ROOT)) except AttributeError: pass try: traps.append(error_handlers.InvalidPaging(proto.INVALID_PAGING)) except AttributeError: pass for trap in traps: trap.check(parsed.status) return cls.message_to_dict(parsed)
def _try_response_parse(proto, response, traps=None): """ Parses a protobuf response from the validator Raises common validator error statuses as HTTP errors """ parsed = proto() parsed.ParseFromString(response) traps = traps or [] try: traps.append(error_handlers.Unknown(proto.INTERNAL_ERROR)) except AttributeError: # Not every protobuf has every status enum, so pass AttributeErrors pass try: traps.append(error_handlers.NotReady(proto.NOT_READY)) except AttributeError: pass try: traps.append(error_handlers.MissingHead(proto.NO_ROOT)) except AttributeError: pass for trap in traps: trap.check(parsed.status) return MessageToDict( parsed, including_default_value_fields=True, preserving_proto_field_name=True, )