mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-08 00:43:06 +00:00
fix: libwaku's invalid waku message error handling (#3301)
This commit is contained in:
parent
9bb567eb0e
commit
8275d70f35
@ -20,6 +20,13 @@ func fromJsonNode*(
|
||||
T: type JsonMessage, jsonContent: JsonNode
|
||||
): Result[JsonMessage, string] =
|
||||
# Visit https://rfc.vac.dev/spec/14/ for further details
|
||||
|
||||
# Check if required fields exist
|
||||
if not jsonContent.hasKey("payload"):
|
||||
return err("Missing required field in WakuMessage: payload")
|
||||
if not jsonContent.hasKey("contentTopic"):
|
||||
return err("Missing required field in WakuMessage: contentTopic")
|
||||
|
||||
ok(
|
||||
JsonMessage(
|
||||
payload: Base64String(jsonContent["payload"].getStr()),
|
||||
|
||||
@ -291,18 +291,17 @@ proc waku_relay_publish(
|
||||
checkLibwakuParams(ctx, callback, userData)
|
||||
|
||||
let jwm = jsonWakuMessage.alloc()
|
||||
defer:
|
||||
deallocShared(jwm)
|
||||
var jsonMessage: JsonMessage
|
||||
try:
|
||||
let jsonContent = parseJson($jwm)
|
||||
jsonMessage = JsonMessage.fromJsonNode(jsonContent).valueOr:
|
||||
raise newException(JsonParsingError, $error)
|
||||
except JsonParsingError:
|
||||
deallocShared(jwm)
|
||||
let msg = fmt"Error parsing json message: {getCurrentExceptionMsg()}"
|
||||
callback(RET_ERR, unsafeAddr msg[0], cast[csize_t](len(msg)), userData)
|
||||
return RET_ERR
|
||||
finally:
|
||||
deallocShared(jwm)
|
||||
|
||||
let wakuMessage = jsonMessage.toWakuMessage().valueOr:
|
||||
let msg = "Problem building the WakuMessage: " & $error
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user