fix(rest): filter/v2/subscriptions response (#2529)

This commit is contained in:
richΛrd 2024-03-18 18:21:06 -04:00 committed by GitHub
parent a576e62401
commit 7aea2d4fc4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 21 deletions

View File

@ -246,7 +246,7 @@ suite "Waku v2 Rest API - Filter V2":
pingResponse.status == 200
$pingResponse.contentType == $MIMETYPE_JSON
pingResponse.data.requestId == "9999"
pingResponse.data.statusDesc.len() == 0
pingResponse.data.statusDesc == "OK"
# When - error case
let requestBodyUnsubAll = FilterUnsubscribeAllRequest(requestId: "9988")
@ -288,7 +288,7 @@ suite "Waku v2 Rest API - Filter V2":
pingResponse.status == 200
$pingResponse.contentType == $MIMETYPE_JSON
pingResponse.data.requestId == "9999"
pingResponse.data.statusDesc.len() == 0
pingResponse.data.statusDesc == "OK"
# When - message push
let testMessage = WakuMessage(

View File

@ -63,9 +63,12 @@ func decodeRequestBody[T](
return ok(requestResult.get())
proc getErrorCause(err: filter_protocol_type.FilterSubscribeError): string =
proc getStatusDesc(protocolClientRes: filter_protocol_type.FilterSubscribeResult): string =
## Retrieve proper error cause of FilterSubscribeError - due stringify make some parts of text double
if protocolClientRes.isOk:
return "OK"
let err = protocolClientRes.error
case err.kind
of FilterSubscribeErrorKind.PEER_DIAL_FAILURE:
err.address
@ -81,16 +84,10 @@ proc convertResponse(
protocolClientRes: filter_protocol_type.FilterSubscribeResult,
): T =
## Properly convert filter protocol's response to rest response
if protocolClientRes.isErr():
return FilterSubscriptionResponse(
requestId: requestId,
statusCode: uint32(protocolClientRes.error().kind),
statusDesc: getErrorCause(protocolClientRes.error()),
)
else:
return
FilterSubscriptionResponse(requestId: requestId, statusCode: 0, statusDesc: "")
return FilterSubscriptionResponse(
requestId: requestId,
statusDesc: getStatusDesc(protocolClientRes),
)
proc convertResponse(
T: type FilterSubscriptionResponse,
@ -98,10 +95,8 @@ proc convertResponse(
protocolClientRes: filter_protocol_type.FilterSubscribeError,
): T =
## Properly convert filter protocol's response to rest response in case of error
return FilterSubscriptionResponse(
requestId: requestId,
statusCode: uint32(protocolClientRes.kind),
statusDesc: $protocolClientRes,
)

View File

@ -47,7 +47,6 @@ type FilterUnsubscribeAllRequest* = object
type FilterSubscriptionResponse* = object
requestId*: string
statusCode*: uint32
statusDesc*: string
#### Type conversion
@ -119,7 +118,6 @@ proc writeValue*(
) {.raises: [IOError].} =
writer.beginRecord()
writer.writeField("requestId", value.requestId)
writer.writeField("statusCode", value.statusCode)
writer.writeField("statusDesc", value.statusDesc)
writer.endRecord()
@ -406,7 +404,6 @@ proc readValue*(
) {.raises: [SerializationError, IOError].} =
var
requestId = none(string)
statusCode = none(uint32)
statusDesc = none(string)
var keys = initHashSet[string]()
@ -423,8 +420,6 @@ proc readValue*(
case fieldName
of "requestId":
requestId = some(reader.readValue(string))
of "statusCode":
statusCode = some(reader.readValue(uint32))
of "statusDesc":
statusDesc = some(reader.readValue(string))
else:
@ -435,6 +430,5 @@ proc readValue*(
value = FilterSubscriptionResponse(
requestId: requestId.get(),
statusCode: statusCode.get(),
statusDesc: statusDesc.get(""),
)