hilla icon indicating copy to clipboard operation
hilla copied to clipboard

[autoform] Handle optimistic locking exceptions

Open Artur- opened this issue 1 year ago • 3 comments

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

Artur- avatar Oct 03 '23 06:10 Artur-

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.

cromoteca avatar Nov 01 '23 11:11 cromoteca

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)
    }
  }

tarekoraby avatar Nov 01 '23 11:11 tarekoraby

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

cromoteca avatar Nov 01 '23 11:11 cromoteca