mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-03 06:23:10 +00:00
simplify libwaku error returns (#3399)
This commit is contained in:
parent
b435b51c4e
commit
2926542fcd
@ -143,7 +143,7 @@ proc process*(
|
||||
of PEER_EXCHANGE:
|
||||
let numValidPeers = (await performPeerExchangeRequestTo(self[].numPeers, waku)).valueOr:
|
||||
error "PEER_EXCHANGE failed", error = error
|
||||
return err("error calling performPeerExchangeRequestTo: " & $error)
|
||||
return err($error)
|
||||
return ok($numValidPeers)
|
||||
|
||||
error "discovery request not handled"
|
||||
|
||||
@ -92,16 +92,16 @@ proc process*(
|
||||
of CREATE_NODE:
|
||||
waku[] = (await createWaku(self.configJson, self.appCallbacks)).valueOr:
|
||||
error "CREATE_NODE failed", error = error
|
||||
return err("error processing createWaku request: " & $error)
|
||||
return err($error)
|
||||
of START_NODE:
|
||||
(await waku.startWaku()).isOkOr:
|
||||
error "START_NODE failed", error = error
|
||||
return err("problem starting waku: " & $error)
|
||||
return err($error)
|
||||
of STOP_NODE:
|
||||
try:
|
||||
await waku[].stop()
|
||||
except Exception:
|
||||
error "STOP_NODE failed", error = getCurrentExceptionMsg()
|
||||
return err("exception stopping node: " & getCurrentExceptionMsg())
|
||||
return err(getCurrentExceptionMsg())
|
||||
|
||||
return ok("")
|
||||
|
||||
@ -104,6 +104,6 @@ proc process*(
|
||||
)
|
||||
).valueOr:
|
||||
error "PUBLISH failed", error = error
|
||||
return err("LightpushRequest error publishing: " & $error)
|
||||
return err($error)
|
||||
|
||||
return ok(msgHashHex)
|
||||
|
||||
@ -113,28 +113,25 @@ proc process*(
|
||||
(kind: SubscriptionKind.PubsubSub, topic: $self.pubsubTopic),
|
||||
handler = some(self.relayEventCallback),
|
||||
).isOkOr:
|
||||
let errorMsg = "Subscribe failed:" & $error
|
||||
error "SUBSCRIBE failed", error = errorMsg
|
||||
return err(errorMsg)
|
||||
error "SUBSCRIBE failed", error
|
||||
return err($error)
|
||||
of UNSUBSCRIBE:
|
||||
waku.node.unsubscribe((kind: SubscriptionKind.PubsubSub, topic: $self.pubsubTopic)).isOkOr:
|
||||
let errorMsg = "Unsubscribe failed:" & $error
|
||||
error "UNSUBSCRIBE failed", error = errorMsg
|
||||
return err(errorMsg)
|
||||
error "UNSUBSCRIBE failed", error
|
||||
return err($error)
|
||||
of PUBLISH:
|
||||
let msg = self.message.toWakuMessage()
|
||||
let pubsubTopic = $self.pubsubTopic
|
||||
|
||||
(await waku.node.wakuRelay.publish(pubsubTopic, msg)).isOkOr:
|
||||
let errorMsg = "Message not sent." & $error
|
||||
error "PUBLISH failed", error = errorMsg
|
||||
return err(errorMsg)
|
||||
error "PUBLISH failed", error
|
||||
return err($error)
|
||||
|
||||
let msgHash = computeMessageHash(pubSubTopic, msg).to0xHex
|
||||
return ok(msgHash)
|
||||
of NUM_CONNECTED_PEERS:
|
||||
let numConnPeers = waku.node.wakuRelay.getNumConnectedPeers($self.pubsubTopic).valueOr:
|
||||
error "NUM_CONNECTED_PEERS failed", error = error
|
||||
error "NUM_CONNECTED_PEERS failed", error
|
||||
return err($error)
|
||||
return ok($numConnPeers)
|
||||
of LIST_CONNECTED_PEERS:
|
||||
@ -164,5 +161,5 @@ proc process*(
|
||||
@[protectedShard], uint16(self.clusterId)
|
||||
)
|
||||
except ValueError:
|
||||
return err("ADD_PROTECTED_SHARD exception: " & getCurrentExceptionMsg())
|
||||
return err(getCurrentExceptionMsg())
|
||||
return ok("")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user