Search in sources :

Example 1 with BadRequestException

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();
}
Also used : ServiceMessage(io.scalecube.services.api.ServiceMessage) BadRequestException(io.scalecube.services.exceptions.BadRequestException)

Aggregations

ServiceMessage (io.scalecube.services.api.ServiceMessage)1 BadRequestException (io.scalecube.services.exceptions.BadRequestException)1