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

View File

@ -63,9 +63,12 @@ func decodeRequestBody[T](
return ok(requestResult.get()) 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 ## 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 case err.kind
of FilterSubscribeErrorKind.PEER_DIAL_FAILURE: of FilterSubscribeErrorKind.PEER_DIAL_FAILURE:
err.address err.address
@ -81,16 +84,10 @@ proc convertResponse(
protocolClientRes: filter_protocol_type.FilterSubscribeResult, protocolClientRes: filter_protocol_type.FilterSubscribeResult,
): T = ): T =
## Properly convert filter protocol's response to rest response ## Properly convert filter protocol's response to rest response
return FilterSubscriptionResponse(
if protocolClientRes.isErr(): requestId: requestId,
return FilterSubscriptionResponse( statusDesc: getStatusDesc(protocolClientRes),
requestId: requestId, )
statusCode: uint32(protocolClientRes.error().kind),
statusDesc: getErrorCause(protocolClientRes.error()),
)
else:
return
FilterSubscriptionResponse(requestId: requestId, statusCode: 0, statusDesc: "")
proc convertResponse( proc convertResponse(
T: type FilterSubscriptionResponse, T: type FilterSubscriptionResponse,
@ -98,10 +95,8 @@ proc convertResponse(
protocolClientRes: filter_protocol_type.FilterSubscribeError, protocolClientRes: filter_protocol_type.FilterSubscribeError,
): T = ): T =
## Properly convert filter protocol's response to rest response in case of error ## Properly convert filter protocol's response to rest response in case of error
return FilterSubscriptionResponse( return FilterSubscriptionResponse(
requestId: requestId, requestId: requestId,
statusCode: uint32(protocolClientRes.kind),
statusDesc: $protocolClientRes, statusDesc: $protocolClientRes,
) )

View File

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