vaadin / hilla

Build better business applications, faster. No more juggling REST endpoints or deciphering GraphQL queries. Hilla seamlessly connects Spring Boot and React to accelerate application development.
https://hilla.dev
Apache License 2.0
923 stars 57 forks source link

[Full-Stack Signals] Operation validation error message is not propagated to the client #2916

Open taefi opened 2 days ago

taefi commented 2 days ago

Describe the bug

When an operation validator is defined for a full-stack signal, no matter what the rejection error is, on the client side, the reason is: "server rejected the operation".

Expected-behavior

To be able to show a the validation error message that is defined for the server-side Signal instance's validator.

Reproduction

Define an operation validator for signal instance that is returned to the client:

private final ListSignal<Message> chatSignal = new ListSignal<>(Message.class).withOperationValidator(
            operation -> {
                if (operation instanceof ValueOperation<Message> valueOp) {
                    if (valueOp.value().text().toLowerCase().contains("bad")) {
                        return ValidationResult.reject("Bad words are not allowed");
                    }
                }
                return ValidationResult.allow();
            });

or even with a readonly signal:

private final ListSignal<Message> guestSignal = chatSignal.asReadonly();

When user tries to insert a message to any of the above signals instances, and the operation validation gets rejected, the only available reason for in the onrejected callback is always: "server rejected the operation":

chatSignal.insertLast({text: 'Hi', author:'John'})
               .result.then(() => {}, (reason) => Notification.show(reason));

System Info

Vaadin: 24.6.0.alpha4 Hilla: 24.6.0.alpha5