use of io.scalecube.services.exceptions.BadRequestException in project scalecube by scalecube.
the class ServiceMethodInvoker method toRequest.
private Object toRequest(ServiceMessage message) {
ServiceMessage request = dataDecoder.apply(message, methodInfo.requestType());
if (!methodInfo.isRequestTypeVoid() && !methodInfo.isRequestTypeServiceMessage() && !request.hasData(methodInfo.requestType())) {
Optional<?> dataOptional = Optional.ofNullable(request.data());
Class<?> clazz = dataOptional.map(Object::getClass).orElse(null);
throw new BadRequestException(String.format("Expected service request data of type: %s, but received: %s", methodInfo.requestType(), clazz));
}
return methodInfo.isRequestTypeServiceMessage() ? request : request.data();
}
Aggregations