use of org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.SubscriptionNotFoundException in project besu by hyperledger.
the class EthUnsubscribe method response.
@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
try {
final UnsubscribeRequest unsubscribeRequest = getMapper().mapUnsubscribeRequest(requestContext);
final boolean unsubscribed = subscriptionManager().unsubscribe(unsubscribeRequest);
return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), unsubscribed);
} catch (final InvalidSubscriptionRequestException isEx) {
return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.INVALID_REQUEST);
} catch (final SubscriptionNotFoundException snfEx) {
return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.SUBSCRIPTION_NOT_FOUND);
} catch (final Exception e) {
return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.INTERNAL_ERROR);
}
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.SubscriptionNotFoundException in project besu by hyperledger.
the class PrivUnsubscribe method response.
@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
try {
final PrivateUnsubscribeRequest unsubscribeRequest = getMapper().mapPrivateUnsubscribeRequest(requestContext);
if (privacyController instanceof MultiTenancyPrivacyController) {
checkIfPrivacyGroupMatchesAuthenticatedPrivacyUserId(requestContext, unsubscribeRequest.getPrivacyGroupId());
}
final boolean unsubscribed = subscriptionManager().unsubscribe(unsubscribeRequest);
return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), unsubscribed);
} catch (final InvalidSubscriptionRequestException isEx) {
return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.INVALID_REQUEST);
} catch (final SubscriptionNotFoundException snfEx) {
return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.SUBSCRIPTION_NOT_FOUND);
}
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.SubscriptionNotFoundException in project besu by hyperledger.
the class EthUnsubscribeTest method whenSubscriptionNotFoundReturnError.
@Test
public void whenSubscriptionNotFoundReturnError() {
final JsonRpcRequestContext request = createJsonRpcRequest();
when(mapperMock.mapUnsubscribeRequest(any())).thenReturn(mock(UnsubscribeRequest.class));
when(subscriptionManagerMock.unsubscribe(any())).thenThrow(new SubscriptionNotFoundException(1L));
final JsonRpcErrorResponse expectedResponse = new JsonRpcErrorResponse(request.getRequest().getId(), JsonRpcError.SUBSCRIPTION_NOT_FOUND);
assertThat(ethUnsubscribe.response(request)).isEqualTo(expectedResponse);
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.SubscriptionNotFoundException in project besu by hyperledger.
the class PrivUnsubscribeTest method whenSubscriptionNotFoundReturnError.
@Test
public void whenSubscriptionNotFoundReturnError() {
final JsonRpcRequestContext request = createPrivUnsubscribeRequest();
when(mapperMock.mapPrivateUnsubscribeRequest(any())).thenReturn(mock(PrivateUnsubscribeRequest.class));
when(subscriptionManagerMock.unsubscribe(any())).thenThrow(new SubscriptionNotFoundException(1L));
final JsonRpcErrorResponse expectedResponse = new JsonRpcErrorResponse(request.getRequest().getId(), JsonRpcError.SUBSCRIPTION_NOT_FOUND);
assertThat(privUnsubscribe.response(request)).isEqualTo(expectedResponse);
}
Aggregations