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
916 stars 58 forks source link

[autoform] Handle optimistic locking exceptions #1427

Open Artur- opened 1 year ago

Artur- commented 1 year ago

If the entity the form is editing has a @Version field and submit/save fails because of using an old entity, there should be an error message stating the issue ("somebody else edited the data") and what the user should do to get a fresh copy to start from

cromoteca commented 12 months ago

Currently (2.4.0.alpha1), we get a 500 response with this message like: "Endpoint 'PersonService' method 'save' execution failure", so there's no way to detect an optimistic locking exception on the client.

tarekoraby commented 12 months ago

As a quick fix for now, would it be good enough to document that people should throw an EndpointException in Java with the appropriate message?

For example, in Java

@Endpoint
public class DataEndpoint {

    public String save(String s) {
        throw new EndpointException("Optimistic locking exception");
    }
}

then in TS


try {
    await DataEndpoint.save("something");
  } catch (error) {
    if (error instanceof EndpointError && (error as EndpointError).message.startsWith("Optimistic locking") ) {
      // do something (e.g., re-fetch data from server)
    }
  }
cromoteca commented 12 months ago

Yes, developers could catch org.springframework.orm.ObjectOptimisticLockingFailureException.