diff --git a/tests/wakunode_rest/test_rest_filter.nim b/tests/wakunode_rest/test_rest_filter.nim index ab6c9c0ba0..7828b9d6b8 100644 --- a/tests/wakunode_rest/test_rest_filter.nim +++ b/tests/wakunode_rest/test_rest_filter.nim @@ -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( diff --git a/waku/waku_api/rest/filter/handlers.nim b/waku/waku_api/rest/filter/handlers.nim index 3d5966b5dc..315a2f948b 100644 --- a/waku/waku_api/rest/filter/handlers.nim +++ b/waku/waku_api/rest/filter/handlers.nim @@ -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, ) diff --git a/waku/waku_api/rest/filter/types.nim b/waku/waku_api/rest/filter/types.nim index e37b5c4a83..19b9e71af7 100644 --- a/waku/waku_api/rest/filter/types.nim +++ b/waku/waku_api/rest/filter/types.nim @@ -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(""), )