Catch PeerDataError in PeerStore.get

This commit is contained in:
NIC619 2019-10-17 15:52:57 +08:00
parent 5063f0e2a6
commit 211e2f6dd0
No known key found for this signature in database
GPG Key ID: 570C35F5C2D51B17

View File

@ -3,7 +3,7 @@ from typing import Any, Dict, List, Optional, Sequence
from multiaddr import Multiaddr
from .id import ID
from .peerdata import PeerData
from .peerdata import PeerData, PeerDataError
from .peerinfo import PeerInfo
from .peerstore_interface import IPeerStore
@ -54,7 +54,10 @@ class PeerStore(IPeerStore):
def get(self, peer_id: ID, key: str) -> Any:
if peer_id in self.peer_map:
try:
val = self.peer_map[peer_id].get_metadata(key)
except PeerDataError as error:
raise PeerStoreError(error)
return val
raise PeerStoreError("peer ID not found")